HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<nav id="navbar">
<header id="main-header">
<h1>Python Tutorial</h1>
</header>
<ul>
<li>
<a href="#Introduction" class="nav-link active">Introduction</a>
</li>
<li><a href="#Getting_Started" class="nav-link">Getting Started</a></li>
<li><a href="#Syntax" class="nav-link">Syntax</a></li>
<li><a href="#Comments" class="nav-link">Comments</a></li>
<li><a href="#Variables" class="nav-link">Variables</a></li>
<li><a href="#Reference" class="nav-link">Reference</a></li>
</ul>
</nav>
<main id="main-doc">
<section class="main-section" id="Introduction">
<header>
<h2>Introduction</h2>
</header>
<article>
<p>
Python is a popular programming language. It was created by Guido
van Rossum, and released in 1991.
<span class="new-line"></span> It is used for:
</p>
<ul>
<li>web development (server-side),</li>
<li>software development,</li>
<li>mathematics,</li>
<li>system scripting.</li>
</ul>
</article>
<article>
<h3>What can Python do?</h3>
<ul>
<li>Python can be used on a server to create web applications.</li>
<li>Python can be used alongside software to create workflows.</li>
<li>
Python can connect to database systems. It can also read and
modify files.
</li>
<li>
Python can be used to handle big data and perform complex
mathematics.
</li>
<li>
Python can be used for rapid prototyping, or for production-ready
software development.
</li>
</ul>
</article>
<article>
<h3>Why Python?</h3>
<ul>
<li>
Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
</li>
<li>Python has a simple syntax similar to the English language.</li>
<li>
Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
</li>
<li>
Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can
be very quick.
</li>
<li>
Python can be treated in a procedural way, an object-orientated
way or a functional way.
</li>
</ul>
</article>
</section>
<section class="main-section" id="Getting_Started">
<header>
<h2>Getting Started</h2>
</header>
<article>
<h3>Python install</h3>
<p>
Many PCs and Macs will have python already installed.
<span class="new-line"></span>
To check if you have python installed on a Windows PC, search in the
start bar for Python or run the following on the Command Line
(cmd.exe):
<code class="console">C:\Users\Your Name>python --version</code>
<span class="new-line"></span> check if you have python installed on
a Linux or Mac, then on linux open the command line or on Mac open
the Terminal and type:
<code class="console">python --version</code>
</p>
</article>
<article>
<h3>Python Quickstart</h3>
<p>
Python is an interpreted programming language, this means that as a
developer you write Python (.py) files in a text editor and then put
those files into the python interpreter to be executed.
<span class="new-line"></span> way to run a python file is like this
on the command line:
<code class="console">C:\Users\Your Name>python helloworld.py</code>
<span class="new-line"></span> "helloworld.py" is the name of your
python file. <span class="new-line"></span>Let's write our first
Python file, called helloworld.py, which can be done in any text
editor.
<code class="editor"
><span class="keyword">print</span>(<span class="str"
>"Hello, World!"</span
>)</code
>
<span class="new-line"></span> as that. Save your file. Open your
command line, navigate to the directory where you saved your file,
and run:
<code class="console">C:\Users\Your Name>python helloworld.py</code>
<span class="new-line"></span> output should read:
<code class="console">Hello, World!</code>
</p>
</article>
</section>
<section class="main-section" id="Syntax">
<header>
<h2>Syntax</h2>
</header>
<article>
<h3>Execute Python Syntax</h3>
<p>
Python syntax can be executed by writing directly in the Command
Line:
<code class="console"
>>>> print("Hello, World!")<span class="new-line"></span> Hello,
World!</code
>
<span class="new-line"></span>
Or by creating a python file on the server, using the .py file
extension, and running it in the Command Line:
<code class="console">C:\Users\Your Name>python myfile.py</code>
</p>
</article>
<article>
<h3>Python Indentation</h3>
<p>
<span class="new-line"></span> refers to the spaces at the beginning
of a code line. <span class="new-line"></span> in other programming
languages the indentation in code is for readability only, the
indentation in Python is very important.
<span class="new-line"></span> uses indentation to indicate a block
of code.example
<code class="editor"
><span class="keyword">if</span> <span class="num">5</span> >
<span class="num">2</span>:<span class="new-line"></span>
<span class="keyword two-word-pad-left">print</span>(<span
class="str"
>"Five is greater than two!"</span
>)</code
>
<span class="new-line"></span> will give you an error if you skip
the indentation: example
<code class="editor incorrect"
><span class="keyword">if</span> <span class="num">5</span> >
<span class="num">2</span>:<span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Five is greater than two!"</span
>)
</code>
<code class="console">
<span class="one-word-pad-left"
>File "demo_indentation_test.py", line 2</span
><span class="new-line"></span
><span class="four-word-pad-left">
print("Five is greater than two!")</span
><span class="new-line"></span>
<span class="eight-word-pad-left">^</span>
<span class="new-line"></span>IndentationError: expected an
indented block</code
>
<span class="new-line"></span> have to use the same number of spaces
in the same block of code, otherwise Python will give you an error:
</p>
</article>
</section>
<section class="main-section" id="Comments">
<header>
<h2>Comments</h2>
</header>
<p>
Comments can be used to explain Python code.
<span class="new-line"></span> can be used to make the code more
readable.
<span class="new-line"></span>
Comments can be used to prevent execution when testing code.
</p>
<article>
<h3>Creating a Comment</h3>
<p>
Comments starts with a #, and Python will ignore them:Example
<code class="editor"
><span class="comment">#This is a comment</span
><span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Hello, World!"</span
>)</code
>
</p>
</article>
<article>
<h3>Multi Line Comments</h3>
<p>
Python does not really have a syntax for multi line comments.
<span class="new-line"></span>
To add a multiline comment you could insert a # for each
line:Example
<code class="editor">
<span class="comment"
>#This is a comment<span class="new-line"></span> #written
in<span class="new-line"></span> #more than just one line</span
><span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Hello, World!"</span
>)
</code>
Or, not quite as intended, you can use a multiline string.<span
class="new-line"
></span>
Since Python will ignore string literals that are not assigned to a
variable, you can add a multiline string (triple quotes) in your
code, and place your comment inside it:
<code class="editor" id="str-comment">
""" <span class="new-line"></span>This is a comment<span
class="new-line"
></span>
written in <span class="new-line"></span>more than just one
line<span class="new-line"></span> """<span
class="new-line"
></span>
<span class="keyword">print</span>(<span class="str"
>"Hello, World!"</span
>)</code
>
</p>
</article>
</section>
<section class="main-section" id="Variables">
<header>
<h2>Variables</h2>
</header>
<article>
<h3>Creating Variables</h3>
<p>
Variables are containers for storing data values.
<span class="new-line"></span> other programming languages, Python
has no command for declaring a variable.<span
class="new-line"
></span>
A variable is created the moment you first assign a value to
it.Example
<code class="editor"
>x = <span class="num">5</span><span class="new-line"></span> y =
<span class="str">"John"</span><span class="new-line"></span>
<span class="keyword">print</span>(x)<span
class="new-line"
></span>
<span class="keyword">print</span>(y)</code
>
<span class="new-line"></span> do not need to be declared with any
particular type and can even change type after they have been set.
<span class="new-line"></span> variables can be declared either by
using single or double quotes:
<code class="editor"
>x = <span class="str">"John"</span
><span class="new-line"></span>
<span class="comment"># is the same as</span
><span class="new-line"></span> x =
<span class="str">'John'</span>
</code>
</p>
</article>
<article>
<h3>Variable Names</h3>
<p>
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume). Rules for Python
variables:
</p>
<ul>
<li>
A variable name must start with a letter or the underscore
character
</li>
<li>A variable name cannot start with a number</li>
<li>
A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
</li>
<li>
Variable names are case-sensitive (age, Age and AGE are three
different variables):Example
</li>
</ul>
<p>
<code class="editor">
<span class="comment">#Legal variable names:</span
><span class="new-line"></span> myvar =
<span class="str">"John"</span>
<span class="new-line"></span> my_var =
<span class="str">"John"</span
><span class="new-line"></span> _my_var =
<span class="str">"John"</span
><span class="new-line"></span> myVar =
<span class="str">"John"</span
><span class="new-line"></span> MYVAR =
<span class="str">"John"</span
><span class="new-line"></span> myvar2 =
<span class="str">"John"</span><span class="new-line"></span>
<span class="comment">#Illegal variable names:</span
><span class="new-line"></span>2myvar =
<span class="str">"John"</span
><span class="new-line"></span> my-var =
<span class="str">"John"</span><span class="new-line"></span> my
var = <span class="str">"John"</span>
</code>
</p>
</article>
<article>
<h3>Assign Value to Multiple Variables</h3>
<p>
<span class="new-line"></span> allows you to assign values to
multiple variables in one line:Example
<code class="editor"
>x, y, z = <span class="str">"Orange", "Banana", "Cherry"</span
><span class="new-line"></span>
<span class="keyword">print</span>(x)<span
class="new-line"
></span>
<span class="keyword">print</span>(y)<span
class="new-line"
></span>
<span class="keyword">print</span>(z)</code
>
<span class="new-line"></span> you can assign the same value to
multiple variables in one line:
<code class="editor"
>x = y = z = <span class="str">"Orange"</span
><span class="new-line"></span>
<span class="keyword">print</span>(x)<span
class="new-line"
></span>
<span class="keyword">print</span>(y)<span
class="new-line"
></span>
<span class="keyword">print</span>(z)</code
>
</p>
</article>
<article>
<h3>Output Variables</h3>
<p>
<span class="new-line"></span> Python print statement is often used
to output variables. <span class="new-line"></span> combine both
text and a variable, Python uses the + character:
<code class="editor"
>x = <span class="str">"awesome"</span
><span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Python is "</span
>
+ x)</code
>
<span class="new-line"></span> can also use the + character to add a
variable to another variable:
<code class="editor"
>x = <span class="str">"Python is "</span
><span class="new-line"></span> y =
<span class="str">"awesome"</span><span class="new-line"></span> z
= x + y<span class="new-line"></span>
<span class="keyword">print</span>(z)</code
>
<span class="new-line"></span> numbers, the + character works as a
mathematical operator:
<code class="editor"
>x = <span class="num">5</span><span class="new-line"></span> y =
<span class="num">10</span><span class="new-line"></span>
<span class="keyword">print</span>(x + y)</code
>
<span class="new-line"></span> you try to combine a string and a
number, Python will give you an error:Example
<code class="editor"
>x = <span class="num">5</span><span class="new-line"></span> y =
<span class="str">"John"</span><span class="new-line"></span>
<span class="keyword">print</span>(x + y)</code
>
</p>
</article>
<article>
<h3>Global Variables</h3>
<p>
Variables that are created outside of a function (as in all of the
examples above) are known as global variables.
<span class="new-line"></span> variables can be used by everyone,
both inside of functions and outside.
<code class="editor"
>x = <span class="str">"awesome"</span
><span class="new-line"></span><span class="new-line"></span>
<span class="keyword">def</span> myfunc():<span
class="new-line"
></span>
<span class="keyword two-word-pad-left">print</span>(<span
class="str"
>"Python is "</span
>
+ x)<span class="new-line"></span
><span class="new-line"></span> myfunc()</code
>
<span class="new-line"></span> you create a variable with the same
name inside a function, this variable will be local, and can only be
used inside the function. The global variable with the same name
will remain as it was, global and with the original value.
<code class="editor"
>x = <span class="str">"awesome"</span
><span class="new-line"></span><span class="new-line"></span>
<span class="keyword">def</span> myfunc():
<span class="new-line"></span
><span class="two-word-pad-left">x =</span>
<span class="str">"fantastic"</span
><span class="new-line"></span>
<span class="keyword two-word-pad-left">print</span>(<span
class="str"
>
"Python is "</span
>
+ x)<span class="new-line"></span
><span class="new-line"></span> myfunc()<span
class="new-line"
></span
><span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Python is "</span
>
+ x)</code
>
</p>
</article>
<article>
<h3>The global Keyword</h3>
<p>
Normally, when you create a variable inside a function, that
variable is local, and can only be used inside that function.
<span class="new-line"></span> create a global variable inside a
function, you can use the global keyword.Example
<code class="editor"
><span class="keyword">def</span> myfunc():<span
class="new-line"
></span>
<span class="keyword two-word-pad-left">global</span> x<span
class="new-line"
></span>
<span class="two-word-pad-left">x =</span>
<span class="str">"fantastic"</span><span class="new-line"></span
><span class="new-line"></span> myfunc()<span
class="new-line"
></span
><span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Python is "</span
>
+ x)
</code>
<span class="new-line"></span>, use the global keyword if you want
to change a global variable inside a function.Example
<code class="editor">
x=<span class="str">"awesome"</span><span class="new-line"></span
><span class="new-line"></span>
<span class="keyword">def</span> myfunc():<span
class="new-line"
></span>
<span class="keyword two-word-pad-left">global</span> x<span
class="new-line"
></span>
<span class="two-word-pad-left">x = </span
><span class="str">"fantastic"</span><span class="new-line"></span
><span class="new-line"></span> myfunc()<span
class="new-line"
></span
><span class="new-line"></span>
<span class="keyword">print</span>(<span class="str"
>"Python is "</span
>
+ x)
</code>
</p>
</article>
</section>
<section class="main-section" id="Reference">
<header>
<h2>Reference</h2>
</header>
<ul>
<li>
All the documentation in this page is taken from
<a href="https://www.w3schools.com/python">w3schools</a>
</li>
</ul>
</section>
</main>
:root {
--pad-left: 10.6px;
}
html {
scroll-behavior: smooth;
}
body {
font-family: Arial, Helvetica, sans-serif;
line-height: 1.5;
margin: 0;
}
h2 {
font-size: 2rem;
font-weight: 400;
margin-top: 0;
padding-top: 26.56px;
}
p,
ul {
color: #333;
}
h3 {
padding-left: 1rem;
font-size: 1.3rem;
font-weight: 400;
}
p {
padding-left: 2rem;
}
ul {
padding-left: 4rem;
}
.one-word-pad-left {
padding-left: var(--pad-left);
}
.two-word-pad-left {
padding-left: calc(2 * var(--pad-left));
}
.four-word-pad-left {
padding-left: calc(4 * var(--pad-left));
}
.eight-word-pad-left {
padding-left: calc(8 * var(--pad-left));
}
.new-line {
display: block;
margin-top: 1.5em;
}
.console .new-line,
.editor .new-line {
margin-top: initial;
}
.num {
color: orangered;
}
.keyword {
color: blue;
}
.str {
color: #aa0000;
}
/* Navbar */
#navbar {
background: rgba(0, 0, 0, 0.9);
height: 100vh;
width: 300px;
position: fixed;
background-color: #111;
}
#navbar h1 {
font-size: 2.2rem;
text-align: center;
color: rgb(160, 0, 0);
font-weight: 400;
}
#navbar ul {
padding-left: 2rem;
}
#navbar ul li {
list-style: none;
}
#navbar .nav-link {
text-decoration: none;
display: block;
color: #fff;
font-size: 1.2rem;
font-weight: 100;
padding: 1rem 0;
}
#navbar .nav-link:hover,
#navbar .active {
animation-name: hover-effect;
animation-duration: 400ms;
animation-fill-mode: forwards;
}
@keyframes hover-effect {
100% {
color: rgb(160, 0, 0);
border-bottom: 1px solid rgb(133, 70, 70);
padding-left: 0.5rem;
}
}
/* Main */
#main-doc {
padding-right: 3rem;
margin-left: 350px;
margin-bottom: 32rem;
}
.main-section {
margin-bottom: 4rem;
}
#Introduction p {
padding-left: 1rem;
}
code.editor,
code.console {
display: block;
background: #f4f4f4;
padding: 1.2rem 1.1rem;
margin: 1rem 0;
margin-left: 1rem;
border-radius: 5px;
font-size: 1.1rem;
line-height: 1.9;
overflow: auto;
white-space: nowrap;
}
code.console {
background: rgb(0, 0, 0);
color: rgb(79, 191, 64);
}
code.incorrect {
background: rgba(255, 0, 0, 0.1);
}
code .comment {
color: green;
}
code#str-comment {
color: #aa0000;
line-height: inherit;
}
/* Media Queries */
/* (max-width:841px) */
@media (max-width: 841px) {
/* Navbar */
#navbar {
position: static;
min-width: 100%;
height: 350px;
overflow-y: scroll;
}
/* Main */
#main-doc {
margin: 0 1rem;
}
}
/* (max-width:551px) */
@media (max-width: 551px) {
h2 {
padding-left: 0.3rem;
}
#main-doc {
margin: 0;
padding-right: 0.8rem;
}
code.editor,
code.console {
margin-left: 0;
}
}
let mainNavLinks = document.querySelectorAll(".nav-link");
window.addEventListener("scroll", (event) => {
let fromTop = window.scrollY;
//while scrolling make the nav-list item <a> state active if in that specific region.
mainNavLinks.forEach((link) => {
let section = document.querySelector(link.hash);
if (
section.offsetTop <= fromTop &&
section.offsetTop + section.offsetHeight >fromTop
) {
link.classList.add("active");
} else {
link.classList.remove("active");
}
});
});
Also see: Tab Triggers