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 URLs 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 its URL and the proper URL extension.
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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<nav id="navbar">
<header>
<h1>Intro to Python</h1>
</header>
<ul>
<li><a href="#Data_Types" class="nav-link">Data Types</a></li>
<li><a href="#Print_a_Message" class="nav-link">Print a Message</a></li>
<li><a href="#Variables" class="nav-link">Variables</a></li>
<li><a href="#Input" class="nav-link">Input</a></li>
<li><a href="#Lists" class="nav-link">Lists</a></li>
<li><a href="#Tuples" class="nav-link">Tuples</a></li>
<li><a href="#Dictionaries" class="nav-link">Dictionaries</a></li>
<li><a href="#Conditions" class="nav-link">Conditions</a></li>
<li><a href="#For_Loops" class="nav-link">For Loops</a></li>
<li><a href="#While_Loops" class="nav-link">While Loops</a></li>
<li><a href="#Functions" class="nav-link">Functions</a></li>
<li><a href="#Classes" class="nav-link">Classes</a></li>
<li><a href="#References" class="nav-link">References</a></li>
</ul>
</nav>
<main id="main-doc">
<section class="main-section" id="Data_Types">
<header>
<h1>Data Types</h1>
</header>
<table>
<thead>
<th>Category</th>
<th>Types</th>
</thead>
<tbody>
<tr>
<td>Text</td>
<td><code>str</code></td>
</tr>
<tr>
<td>Numeric</td>
<td><code>int</code>, <code>float</code>, <code>complex</code></td>
</tr>
<tr>
<td>Sequence</td>
<td><code>list</code>, <code>tuple</code>, <code>range</code></td>
</tr>
<tr>
<td>Mapping</td>
<td><code>dict</code></td>
</tr>
<tr>
<td>Set</td>
<td><code>set</code>, <code>frozenset</code></td>
</tr>
<tr>
<td>Boolean</td>
<td><code>bool</code></td>
</tr>
<tr>
<td>Binary</td>
<td><code>bytes</code>, <code>bytearray</code>, <code>memoryview</code></td>
</tr>
</tbody>
</table>
</section>
<section class="main-section" id="Print_a_Message">
<header>
<h1>Print a Message</h1>
</header>
<p>You can print a message onto the screen with the <code>print()</code> function</p>
<p>For example, to print a <em>string</em> value:</p>
<pre>print("Hello World!")</pre>
<p><samp>Hello World!</samp></p>
<p>You can print numbers and operations:</p>
<pre>print(5 + 2)</pre>
<p><samp>7</samp></p>
<pre>print(5 * 2)</pre>
<p><samp>10</samp></p>
<pre>print(3 ** 3)</pre>
<p><samp>27</samp></p>
<p>You can print many values at once:</p>
<pre>print("Hi", 3 + 1)</pre>
<p><samp>Hi 4</samp></p>
</section>
<section class="main-section" id="Variables">
<header>
<h1>Variables</h1>
</header>
<p>When you are programming, there are many situations in which you have to use a value many times or save it. Instead of <a href="https://en.wikipedia.org/wiki/Hard_coding" target="_blank">hard-coding</a> that value you can use variables. Let's see an example:</p>
<pre>x = "Hello" # This is how a variable is declared</pre>
<p>You can print variables and operate with them:</p>
<pre>x = 5<br>print(x)</pre>
<p><samp>5</samp></p>
<pre>print(x - 3)</pre>
<p><samp>2</samp></p>
<pre>x = 42<br>y = 50<br>print(x + y)</pre>
<p><samp>92</samp></p>
<pre>x = 15<br>y = 2 * x<br>print(y)</pre>
<p><samp>30</samp></p>
</div>
</section>
<section class="main-section" id="Input">
<header>
<h1>Input</h1>
</header>
<p>With the <code>input()</code> function, the user can enter a value and save it in a variable. Let's see an example:</p>
<pre>my_example = input()<br>print(my_example)</pre>
<p><kbd>Hello!</kbd></p>
<p><samp>Hello!</samp></p>
<p>But when a number is entered and you want to operate with it, the operations will not work because the <code>input()</code> function returns <em>string</em> values. To solve this, before writing <code>input()</code>, specify the data type:</p>
<pre>float(input()) # For example</pre>
<p>Also, you can write a message to specify to the user what to enter. For example:</p>
<pre>name = input("Enter your name: ")</pre>
<p><kbd>Enter your name: </kbd></p>
</section>
<section class="main-section" id="Lists">
<header>
<h1>Lists</h1>
</header>
<p>Lists are ordered and changeable collections. They are written with square brackets. Let's see an example:</p>
<pre>my_list = ["Literature" , "Music" , "Films" , "TV" , "Videogames"]</pre>
<p>You can access the items by referring to the index number <u>(the first position is 0)</u>:</p>
<pre>print(my_list[1])</pre>
<p><samp>Music</samp></p>
<p>When you write a negative index like <code>-1</code>, you will get the last item, with <code>-2</code>, the second last item...</p>
<pre>print(my_list[-1])</pre>
<p><samp>Videogames</samp></p>
<p>You can use a range of indexes:</p>
<pre>print(my_list[2:4])</pre>
<p><samp>['Films', 'TV']</samp></p>
<p>Lists are changeable and there are many methods. Let's see some of them:</p>
<p><code>append()</code> Adds an element at the end of the list:</p>
<pre>my_list.append("Radio")<br>print(my_list)</pre>
<p><samp>['Literature', 'Music', 'Films', 'TV', 'Videogames', 'Radio']</samp></p>
<p><code>pop()</code> Removes the element at the specified position:</p>
<pre>my_list = ["Literature" , "Music" , "Films" , "TV" , "Videogames"]<br>my_list.pop(1)<br>print(my_list)</pre>
<p><samp>['Literature', 'Films', 'TV', 'Videogames']</samp></p>
<p>You can check more list methods at:</p>
<ul>
<li><a href="https://docs.python.org/3/tutorial/datastructures.html#more-on-lists" target="_blank">Python Docs</a></li>
<li><a href="https://www.w3schools.com/python/python_ref_list.asp" target="_blank">W3Schools</a></li>
</ul>
</section>
<section class="main-section" id="Tuples">
<header>
<h1>Tuples</h1>
</header>
<p>Tuples, like lists, are collections that are ordered but <strong>UNCHANGEABLE</strong>. Tuples are written with round brackets:</p>
<pre>my_tuple = ("Literature" , "Music" , "Films" , "TV" , "Videogames")</pre>
<p>The only way to modify a tuple is by transforming it into a list and then into a tuple. Let's see an example:</p>
<pre>my_tuple = ("Literature" , "Music" , "Films" , "TV" , "Videogames")<br>my_tuple = list(my_tuple)<br>my_tuple.pop()<br>my_tuple = tuple(my_tuple)<br>print(my_tuple)</pre>
<p><samp>('Literature', 'Music', 'Films', 'TV')</samp></p>
</section>
<section class="main-section" id="Dictionaries">
<header>
<h1>Dictionaries</h1>
</header>
<p>Dictionaries are unordered, changeable and indexed. They have keys and values. Let's see an example:</p>
<pre>my_dictionary = {<br> "Name": "Fredrick D. Thomas",<br> "Occupation": "Electronic technician",<br> "Age": "34"<br>}</pre>
<p>You can access an item by referring to its key name:</p>
<pre>print(my_dictionary["Age"])</pre>
<p><samp>34</samp></p>
<p>You can add and modify values:</p>
<pre>my_dictionary["Country"] = "USA"<br>print(my_dictionary)</pre>
<p><samp>{'Name': 'Fredrick D. Thomas', 'Occupation': 'Electronic technician', 'Age': '34', 'Country': 'USA'}</samp></p>
<p>You can check dictionary methods at:</p>
<ul>
<li><a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries" target="_blank">Python Docs</a></li>
<li><a href="https://www.w3schools.com/python/python_ref_dictionary.asp" target="_blank">W3Schools</a></li>
</ul>
</section>
<section class="main-section" id="Conditions">
<header>
<h1>Conditions</h1>
</header>
<p>Conditions always return a Boolean value</p>
<table>
<caption>Logical Conditions</caption>
<tr>
<td>Equals</td>
<td><code>a == b</code></td>
</tr>
<tr>
<td>Not Equals</td>
<td><code>a != b</code></td>
</tr>
<tr>
<td>Less than</td>
<td><code>a < b</code></td>
</tr>
<tr>
<td>Less than or equal to</td>
<td><code>a <= b</code></td>
</tr>
<tr>
<td>Greater than</td>
<td><code>a > b</code></td>
</tr>
<tr>
<td>Greater than or equal to</td>
<td><code>a >= b</code></td>
</tr>
</table>
<p>Let's see how to write a condition:</p>
<pre>a = 100<br>b = 50<br><br>if a > b:<br> print("a is greater than b")</pre>
<p><samp>a is greater than b</samp></p>
<p>When the <var>b</var> variable is greater than the <var>a</var> variable we can use <code>else</code>. Let's see an example:</p>
<pre>a = 50<br>b = 100<br><br>if a > b:<br> print("a is greater than b")<br>else:<br> print("b is greater than a")</pre>
<p><samp>b is greater than a</samp></p>
<p>But with this conditional statement, when <var>a</var> and <var>b</var> are equal, the program will return <samp>b is greater than a</var></samp> because the condition returns <code>false</code> in that case. We can solve this with <code>elif</code>, it's a second condition in case the first condition is not met. Let's see an example:</p>
<pre>a = 50<br>b = 50<br><br>if a > b:<br> print("a is greater than b")<br>elif a == b:<br> print("a and b are equals")<br>else:<br> print("b is greater than a")</pre>
<p><samp>a and b are equals</samp></p>
<p>If you want to combine many conditional statements, you can use the <code>and</code> keyword. Let's see an example:</p>
<pre>a = 50<br>b = 50<br>c = 40<br><br>if a > c and b > c:<br> print("a and b are greater than c")<br>else:<br> print("Nothing")</pre>
<p><samp>a and b are greater than c</samp></p>
<pre>a = 50<br>b = 30<br>c = 40<br><br>if a > c and b > c:<br> print("a and b are greater than c")<br>else:<br> print("Nothing")</pre>
<p><samp>Nothing</samp></p>
<p>If you want to combine many conditional statements and <u>at least one</u> of those must be met, you can use the <code>or</code> keyword. Let's see an example:</p>
<pre>a = 50<br>b = 30<br>c = 40<br><br>if a > c or b > c:<br> print("a, b or both are greater than c")</pre>
<p><samp>a, b or both are greater than c</samp></p>
<p>You can use conditions to check if there is a value in a list:</p>
<pre>my_list = ["Literature" , "Music" , "Films" , "TV" , "Videogames"]<br><br>if "Music" in my_list:<br> print("Yes, Music is in the list")</pre>
<p><samp>Yes, Music is on the list</samp></p>
</section>
<section class="main-section" id="For_Loops">
<header>
<h1>For Loops</h1>
</header>
<p><code>for</code> loops are used when you have a block of code that you want to repeat a fixed number of times. For example:</p>
<pre>for x in range(5): # You can rename the `x`<br> print("Hi")</pre>
<p><samp>Hi<br>Hi<br>Hi<br>Hi<br>Hi</samp></p>
<p>Instead of the <code>range()</code> function, you can pass a list, tuple... The number of iterations depends on the number of elements in the collection:</p>
<pre>animals = ("cat" , "dog")<br><br>for animal in animals:<br> print(animal) # `animal` -> element of an iteration</pre>
<p><samp>cat<br>dog</samp></p>
</section>
<section class="main-section" id="While_Loops">
<header>
<h1>While Loops</h1>
</header>
<p><code>while</code> loops are used when you have a block of code that you want to repeat infinitely or as long as a Boolean value is truthy. For example:</p>
<pre>while 4 < 10:<br> print("Hi")</pre>
<p><samp>Hi<br>Hi<br>Hi<br>Hi<br>Hi<br>Hi<br>Hi<br>Hi<br>Hi<br>...</samp></p>
<p>We can use the <code>break</code> statement to stop the loop even if the <code>while</code> expression is truthy:</p>
<pre>x = 1<br><br>while x < 10:<br> print("Hi")<br> x += 1<br> if x > 2:<br> break</pre>
<p><samp>Hi<br>Hi</samp></p>
</section>
<section class="main-section" id="Functions">
<header>
<h1>Functions</h1>
</header>
<p>A function is a block of code that only runs when it is called. For example:</p>
<pre>def my_function():<br> print("Hello")<br><br>my_function()</pre>
<p><samp>Hello</samp></p>
<p>You can add arguments:</p>
<pre>def sum(n1, n2):<br> print(n1 + n2)<br><br>sum(3, 5)</pre>
<p><samp>8</samp></p>
<p>If you don't know how many arguments you will need. You can add a <code>*</code> before the parameter name:</p>
<pre>def sum(*nums):<br> print(nums[3] + nums[5])<br><br>sum(2, 5, 7, 8, 4, 1)</pre>
<p><samp>9</samp></p>
<p>You can use the <code>return</code> statement to return a value:</p>
<pre>def multiply_by_3(number):<br> return number * 3<br><br>print(multiply_by_3(5))<br>print(multiply_by_3(7))<br>print(multiply_by_3(2))</pre>
<p><samp>15<br>21<br>6</samp></p>
</section>
<section class="main-section" id="Classes">
<header>
<h1>Classes</h1>
</header>
<p>Python, like other programming languages, is an <u>object-oriented programming language</u>. You can create an object with classes. Classes are object constructors. Let's see an example:</p>
<pre>class Car:<br> wheels = 4<br><br>my_car = Car()</pre>
<p>We have created an object called <var>my_car</var> with the <var>Car</var> class.</p>
<p>We can print the value of the <var>wheels</var> property:</p>
<pre>print(my_car.wheels)</pre>
<p><samp>4</samp></p>
<p>With the <code>__init__</code> method we can assign values to objects:</p>
<pre>class Battery:<br> def __init__(self, voltage, size):<br> self.voltage = voltage<br> self.size = size<br><br>my_battery = Battery(1.5, "AA")</pre>
<p>We can create a function inside a class:</p>
<pre>class Battery:<br> def __init__(self, voltage, size):<br> self.voltage = voltage<br> self.size = size<br> def get_info(self):<br> print(self.voltage, self.size)<br><br>my_battery = Battery(1.5, "AA")<br>my_battery.get_info()</pre>
<p><samp>1.5 AA</samp></p>
<p>We can modify the properties of an object:</p>
<pre>my_battery.voltage = 3</pre>
<p>We can delete a property or an object with the <code>del</code> statement:</p>
<pre>del my_battery.size</pre>
</section>
<section class="main-section" id="References">
<header>
<h1>References</h1>
</header>
<ul>
<li><a href="https://docs.python.org/3/" target="_blank">Python Docs</a></li>
<li><a href="https://wiki.python.org/moin/" target="_blank">Python Wiki</a></li>
<li><a href="https://www.w3schools.com/python/" target="_blank">W3Schools</a></li>
</ul>
</section>
</main>
html {
scroll-behavior: smooth;
scroll-padding-top: 1.25rem;
}
body {
font-family: Arial, "Lucida Sans Unicode", sans-serif;
background-color: rgb(5, 10, 15);
color: LightCyan;
line-height: 1.5;
margin: 0;
}
#navbar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
overflow: auto;
background-color: rgb(10, 15, 20);
padding-bottom: 1em;
border-right: thin solid SpringGreen;
scrollbar-color: CadetBlue transparent;
scrollbar-width: thin;
}
#navbar > header:first-of-type {
margin: 0 1.5em;
}
#navbar > ul {
list-style: none;
padding: 0;
margin: 0;
}
#navbar a {
display: block;
text-decoration: none;
transition-property: color, background-color;
transition-duration: .15s;
color: LightSeaGreen;
padding: .5em 1.5em;
}
#navbar a:hover {
color: MediumAquaMarine;
background-color: rgb(25, 35, 45);
}
#navbar a:focus {
color: Black;
background-color: MediumSpringGreen;
}
#main-doc {
margin-right: 1rem;
margin-left: 16em;
margin-bottom: 4em;
}
.main-section:not(:first-child) {
margin-top: 3em;
}
.main-section a {
text-decoration: none;
color: DarkCyan;
transition: color .15s;
}
.main-section a:hover {
text-decoration: underline;
color: LightSeaGreen;
}
.main-section a:focus {
text-decoration: underline;
color: MediumAquaMarine;
}
.main-section table {
border-collapse: collapse;
}
.main-section thead {
background-color: rgb(30, 40, 50);
}
.main-section tbody {
background-color: rgb(20, 25, 30);
}
.main-section td, .main-section th, .main-section caption {
border: thin solid DarkCyan;
padding: .5em;
}
.main-section table > caption {
background-color: rgb(30, 40, 60);
font-style: italic;
border-bottom: none
}
.main-section code, .main-section var, .main-section em {
color: Lime;
}
.main-section pre {
max-width: max-content;
color: springgreen;
background-color: rgb(15, 15, 15);
padding: 1em;
border: thin solid DarkSlateGray;
border-left-width: thick;
overflow: auto;
scrollbar-color: CadetBlue transparent;
scrollbar-width: thin;
}
.main-section samp {
color: cadetblue;
}
.main-section ul {
display: grid;
gap: .5em;
list-style-type: circle;
}
.main-section u {
text-decoration-color: MediumSpringGreen;
}
.main-section kbd {
color: MediumAquaMarine;
}
.main-section kbd::before {
content: "> ";
color: Teal;
}
.main-section kbd::after {
content: "";
display: inline-block;
vertical-align: middle;
width: .25em;
height: 1em;
background: Aquamarine;
border-radius: 1px;
box-shadow: 0 0 4px Aquamarine;
margin-left: .2em;
animation: caret 1s infinite step-end;
}
@keyframes caret {
50% {
opacity: 0;
}
}
@media(max-width: 868px) {
#navbar {
position: static;
border-right: none;
border-bottom: thin solid SpringGreen;
margin-bottom: 2em;
}
#main-doc {
margin-left: 1rem;
}
}
const projectName = "technical-docs-page";
Also see: Tab Triggers