This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheatsheet.html
382 lines (378 loc) · 25 KB
/
cheatsheet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>python cheatsheet</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(title);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Didact+Gothic" rel="stylesheet">
<style>
body{
background-color: #f2f2f2;
}
p{
color:#262424;
font-family: 'Source Sans Pro', sans-serif;
}
h1, h2, h3, h4, h5, h6{
color:#262424;
font-family: 'Didact Gothic', sans-serif;
}
blockquote {
background: #f9f9f9;
border-left: 10px solid #ccc;
margin: 1.5em 10px;
padding: 0.5em 10px;
quotes: "\201C""\201D""\2018""\2019";
}
table {
border-collapse: collapse;
}
table td {
border: 3px solid black;
}
th, tr{
font-family: 'Source Sans Pro'
}
</style>
<h1 id="my-python-cheatsheet">My Python Cheatsheet!</h1>
<p>find sentdex <a href="https://pythonprogramming.net">here</a></p>
<h2 id="what-exactly-is-python">What Exactly is Python?</h2>
<ul>
<li><p>python is a general purpose programming language that was built on C to be written very fast.</p></li>
<li><p>there is legacy python2 and python3, which is what will be covered here</p></li>
</ul>
<blockquote>
<p>note: <br> Python uses indentation to indicate blocks of code</p>
</blockquote>
<h4 id="print-statements">Print Statements</h4>
<p>printing is super easy, its just:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb1-1" title="1"><span class="bu">print</span>(<span class="st">"hello world"</span>)</a></code></pre></div>
<h4 id="variables">Variables</h4>
<p>A variable is created as soon as you first assign a value to it</p>
<p>for example:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb2-1" title="1">x<span class="op">=</span><span class="dv">5</span></a>
<a class="sourceLine" id="cb2-2" title="2">y<span class="op">=</span><span class="st">"fedora"</span></a></code></pre></div>
<p>variables don’t need to be defined with a type</p>
<p>they can even change after the variable has been set</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb3-1" title="1">x<span class="op">=</span><span class="dv">4</span></a>
<a class="sourceLine" id="cb3-2" title="2">x<span class="op">=</span>spacemacs</a></code></pre></div>
<p>first variable <code>x</code> was of type <code>int</code></p>
<p>after assigning a new value to <code>x</code>, it became type <code>str</code></p>
<blockquote>
<p>note: you can use <code>+</code> to concat just like in java, and can also use it join variables together(that are of the same type)</p>
</blockquote>
<p>it is possible to define types for variables, using casting</p>
<p>for example:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb4-1" title="1"> x <span class="op">=</span> <span class="bu">int</span>(<span class="dv">1</span>) <span class="co"># x will be 1</span></a>
<a class="sourceLine" id="cb4-2" title="2">y <span class="op">=</span> <span class="bu">int</span>(<span class="fl">2.8</span>) <span class="co"># y will be 2</span></a>
<a class="sourceLine" id="cb4-3" title="3">z <span class="op">=</span> <span class="bu">int</span>(<span class="st">"3"</span>) <span class="co"># z will be 3</span></a></code></pre></div>
<p>this will work for other types as well</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb5-1" title="1">x <span class="op">=</span> <span class="bu">float</span>(<span class="dv">1</span>) <span class="co"># x will be 1.0</span></a>
<a class="sourceLine" id="cb5-2" title="2">y <span class="op">=</span> <span class="bu">float</span>(<span class="fl">2.8</span>) <span class="co"># y will be 2.8</span></a>
<a class="sourceLine" id="cb5-3" title="3">z <span class="op">=</span> <span class="bu">float</span>(<span class="st">"3"</span>) <span class="co"># z will be 3.0</span></a>
<a class="sourceLine" id="cb5-4" title="4">w <span class="op">=</span> <span class="bu">float</span>(<span class="st">"4.2"</span>) <span class="co"># w will be 4.2</span></a></code></pre></div>
<h5 id="variable-names">Variable Names</h5>
<ul>
<li><p>a variable must start with a letter or <code>_</code></p></li>
<li><p>a variable cannot start with a number</p></li>
<li><p>variables can only be alpha-numberic</p></li>
<li><p>variable names are case-sensitive <code>AGE</code> and <code>age</code> are different</p></li>
</ul>
<h4 id="data-types">Data Types</h4>
<p>tuples are like lists, but cannot be changed later on</p>
<blockquote>
<p>note: they are more lightweight than lists</p>
</blockquote>
<p>you can make one like this:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb6-1" title="1">langs<span class="op">=</span> <span class="st">"python"</span>, <span class="st">"java"</span>, <span class="st">"perl"</span></a></code></pre></div>
<p>The <code>langs</code> variable is of the type <code>tuple</code></p>
<p>if you want to check the type of an object/variable in</p>
<p>python, you can use this:</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb7-1" title="1"><span class="bu">type</span>(programming_languages)</a></code></pre></div>
<p>this will return the type, you can print this out</p>
<p>so running this:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb8-1" title="1">langs<span class="op">=</span> <span class="st">"python"</span>, <span class="st">"Java"</span>, <span class="st">"Perl"</span></a>
<a class="sourceLine" id="cb8-2" title="2"><span class="bu">print</span>(<span class="bu">type</span>(langs))</a></code></pre></div>
<p>will return</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb9-1" title="1"><span class="op"><</span><span class="kw">class</span> <span class="st">'tuple'</span><span class="op">></span></a></code></pre></div>
<p>other data types are just like java</p>
<p>for example:</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb10-1" title="1">distro<span class="op">=</span> <span class="st">"void"</span></a>
<a class="sourceLine" id="cb10-2" title="2"><span class="bu">print</span>(<span class="bu">type</span>(distro))</a></code></pre></div>
<p>will return:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb11-1" title="1"><span class="op"><</span><span class="kw">class</span> <span class="st">'str'</span><span class="op">></span></a></code></pre></div>
<h4 id="strings">Strings</h4>
<p>strings can be surrounded by single or double quotes</p>
<p><code>'hello'</code> and <code>"hello"</code> are both valid</p>
<h5 id="string-methods">String Methods</h5>
<p>there are many string methods which are similar to java</p>
<p>Get the character at position 1</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb12-1" title="1">a <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb12-2" title="2"><span class="bu">print</span>(a[<span class="dv">1</span>])</a></code></pre></div>
<p>this is substring, gets the characters</p>
<p>from postion 2 to postion 5</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb13-1" title="1">b <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb13-2" title="2"><span class="bu">print</span>(b[<span class="dv">2</span>:<span class="dv">5</span>])</a></code></pre></div>
<p>the <code>strip()</code> method will remove any whitespaces</p>
<p>from the beginning and end of a string</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb14-1" title="1">a <span class="op">=</span> <span class="st">" Hello, World! "</span></a>
<a class="sourceLine" id="cb14-2" title="2"><span class="bu">print</span>(a.strip()) <span class="co"># returns "Hello, World!" </span></a></code></pre></div>
<p>the <code>len()</code> method will return the length of a string</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb15-1" title="1">a <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb15-2" title="2"><span class="bu">print</span>(<span class="bu">len</span>(a))</a></code></pre></div>
<p>the <code>lower()</code> method will return the string in lowercase</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb16-1" title="1">a <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb16-2" title="2"><span class="bu">print</span>(a.lower())</a></code></pre></div>
<p>the <code>upper()</code> method will return in uppercase</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb17-1" title="1">a <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb17-2" title="2"><span class="bu">print</span>(a.upper())</a></code></pre></div>
<p>the <code>replace()</code> method will replace the first arg by the 2nd arg</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb18-1" title="1">a <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb18-2" title="2"><span class="bu">print</span>(a.replace(<span class="st">"H"</span>, <span class="st">"J"</span>)) </a></code></pre></div>
<blockquote>
<p>note: this happens at all occurances</p>
</blockquote>
<p>the <code>split()</code> method will split the string into substrings</p>
<p>if it finds instances of the seperator(the argument passed)</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb19-1" title="1"> a <span class="op">=</span> <span class="st">"Hello, World!"</span></a>
<a class="sourceLine" id="cb19-2" title="2"><span class="bu">print</span>(a.split(<span class="st">","</span>)) <span class="co"># returns ['Hello', ' World!'] </span></a></code></pre></div>
<h4 id="operators">Operators</h4>
<blockquote>
<p>This is going to be a LONG section</p>
</blockquote>
<p>Operators are used to perform <em>operations</em></p>
<p>python divides operators into different groups</p>
<ul>
<li><p>Arithmatic</p></li>
<li><p>Assignment</p></li>
<li><p>Comparison</p></li>
<li><p>Logical</p></li>
<li><p>Identity</p></li>
<li><p>Membership</p></li>
<li><p>Bitwise</p></li>
</ul>
<h5 id="arithmatic-operators">Arithmatic Operators</h5>
<table>
<thead>
<tr class="header">
<th>operator</th>
<th>name</th>
<th>example</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>+</td>
<td>addition</td>
<td>x+y</td>
</tr>
<tr class="even">
<td>-</td>
<td>subtraction</td>
<td>x-y</td>
</tr>
<tr class="odd">
<td>*</td>
<td>multiplication</td>
<td>x*y</td>
</tr>
<tr class="even">
<td>/</td>
<td>division</td>
<td>x/y</td>
</tr>
<tr class="odd">
<td>%</td>
<td>modulus (remainder)</td>
<td>x%y</td>
</tr>
<tr class="even">
<td>**</td>
<td>exponent</td>
<td>x**y</td>
</tr>
<tr class="odd">
<td>//</td>
<td>floor division</td>
<td>x//y</td>
</tr>
</tbody>
</table>
<h4 id="for-loops">For Loops</h4>
<p>We can loop over different elements</p>
<p>in the tuple as well!</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb20-1" title="1"><span class="cf">for</span> language <span class="kw">in</span> programming_languages:</a></code></pre></div>
<p>the variable name is <code>language</code> and the tuple name is</p>
<p><code>programming_languages</code></p>
<p>all we are doing is iterating over the tuple</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb21-1" title="1">programming_languages <span class="op">=</span> <span class="st">"Python"</span>, <span class="st">"Java"</span>, <span class="st">"C++"</span>, <span class="st">"C#"</span></a>
<a class="sourceLine" id="cb21-2" title="2"></a>
<a class="sourceLine" id="cb21-3" title="3"><span class="cf">for</span> language <span class="kw">in</span> programming_languages:</a>
<a class="sourceLine" id="cb21-4" title="4"> <span class="bu">print</span>(language)</a></code></pre></div>
<p>the code above will output</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb22-1" title="1">Python</a>
<a class="sourceLine" id="cb22-2" title="2">Java</a>
<a class="sourceLine" id="cb22-3" title="3">C<span class="op">++</span></a>
<a class="sourceLine" id="cb22-4" title="4">C<span class="co">#</span></a></code></pre></div>
<h4 id="functions">functions</h4>
<p>these are very very similar to java’s <em>methods</em></p>
<div class="sourceCode" id="cb23"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb23-1" title="1"><span class="co"># Defines a "repeat" function that takes 2 arguments.</span></a>
<a class="sourceLine" id="cb23-2" title="2"><span class="kw">def</span> repeat(s, exclaim):</a>
<a class="sourceLine" id="cb23-3" title="3"> <span class="co">"""</span></a>
<a class="sourceLine" id="cb23-4" title="4"><span class="co"> Returns the string 's' repeated 3 times.</span></a>
<a class="sourceLine" id="cb23-5" title="5"><span class="co"> If exclaim is true, add exclamation marks.</span></a>
<a class="sourceLine" id="cb23-6" title="6"><span class="co"> """</span></a>
<a class="sourceLine" id="cb23-7" title="7"></a>
<a class="sourceLine" id="cb23-8" title="8"> result <span class="op">=</span> s <span class="op">+</span> s <span class="op">+</span> s <span class="co"># can also use "s * 3" which is faster (Why?)</span></a>
<a class="sourceLine" id="cb23-9" title="9"> <span class="cf">if</span> exclaim:</a>
<a class="sourceLine" id="cb23-10" title="10"> result <span class="op">=</span> result <span class="op">+</span> <span class="st">'!!!'</span></a>
<a class="sourceLine" id="cb23-11" title="11"> <span class="cf">return</span> result</a></code></pre></div>
<p>here is the code that is being run:</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb24-1" title="1"><span class="kw">def</span> main():</a>
<a class="sourceLine" id="cb24-2" title="2"> <span class="bu">print</span> repeat(<span class="st">'Yay'</span>, <span class="va">False</span>) <span class="co">## YayYayYay</span></a>
<a class="sourceLine" id="cb24-3" title="3"> <span class="bu">print</span> repeat(<span class="st">'Woo Hoo'</span>, <span class="va">True</span>) <span class="co">## Woo HooWoo HooWoo Hoo!!!</span></a></code></pre></div>
<blockquote>
<p>note: python does very little checking at compile time</p>
</blockquote>
<h4 id="the-len-function">the len() function</h4>
<p>this will return the length of a string</p>
<p>or a tuple. For example:</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb25-1" title="1">distro<span class="op">=</span> <span class="st">"void"</span> </a>
<a class="sourceLine" id="cb25-2" title="2"><span class="bu">print</span>(<span class="st">"length is "</span><span class="op">+</span><span class="bu">str</span>(<span class="bu">len</span>(distro)))</a></code></pre></div>
<p>will return:</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb26-1" title="1"><span class="co">"length is 4"</span></a></code></pre></div>
<h4 id="if-else-statements">if-else statements</h4>
<p>if and else are very similar to java as well,</p>
<p>here is an example program:</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb27-1" title="1">age <span class="op">=</span> <span class="bu">int</span>(<span class="bu">input</span>(<span class="st">"what is your age "</span>))</a>
<a class="sourceLine" id="cb27-2" title="2"></a>
<a class="sourceLine" id="cb27-3" title="3"><span class="cf">if</span> age <span class="op"><</span> <span class="dv">18</span> <span class="kw">and</span> age <span class="op">></span> <span class="dv">5</span> :</a>
<a class="sourceLine" id="cb27-4" title="4"> <span class="bu">print</span>(<span class="st">"you are not allowed to vote yet"</span>)</a>
<a class="sourceLine" id="cb27-5" title="5"></a>
<a class="sourceLine" id="cb27-6" title="6"><span class="cf">elif</span> age<span class="op"><</span><span class="dv">5</span> :</a>
<a class="sourceLine" id="cb27-7" title="7"> <span class="bu">print</span>(<span class="st">"how are you even typing?"</span>)</a>
<a class="sourceLine" id="cb27-8" title="8"></a>
<a class="sourceLine" id="cb27-9" title="9"><span class="cf">elif</span> age <span class="op">>=</span> <span class="dv">18</span> :</a>
<a class="sourceLine" id="cb27-10" title="10"> <span class="bu">print</span>(<span class="st">"you are old enough to vote"</span>)</a></code></pre></div>
<p>this program shows if else statements in action</p>
<p>this code will return:</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb28-1" title="1">how are you even typing?</a></code></pre></div>
<blockquote>
<p>note: <br> to do <code>elseif</code> like in java, its actually: <br> <code>elif</code></p>
</blockquote>
<blockquote>
<p>fun fact: <br> if else statements are quite a meme in ftc 14020</p>
</blockquote>
<h3 id="user-input">User Input</h3>
<p>Lets keep going with this if else program.</p>
<p>How about we ask the user their age?</p>
<p>you can get user input using</p>
<p>for strings</p>
<div class="sourceCode" id="cb29"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb29-1" title="1"><span class="bu">input</span>() </a></code></pre></div>
<p>so we can feed this input into a variable and use this for our little test program:</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb30-1" title="1">age <span class="op">=</span> <span class="bu">int</span>(<span class="bu">input</span>(<span class="st">"what is your age "</span>))</a>
<a class="sourceLine" id="cb30-2" title="2"></a>
<a class="sourceLine" id="cb30-3" title="3"><span class="cf">if</span> age <span class="op"><</span> <span class="dv">18</span> <span class="kw">and</span> age <span class="op">></span> <span class="dv">5</span> :</a>
<a class="sourceLine" id="cb30-4" title="4"> <span class="bu">print</span>(<span class="st">"you are not allowed to vote yet"</span>)</a>
<a class="sourceLine" id="cb30-5" title="5"></a>
<a class="sourceLine" id="cb30-6" title="6"><span class="cf">elif</span> age<span class="op"><</span><span class="dv">5</span> :</a>
<a class="sourceLine" id="cb30-7" title="7"> <span class="bu">print</span>(<span class="st">"how are you even typing?"</span>)</a>
<a class="sourceLine" id="cb30-8" title="8"></a>
<a class="sourceLine" id="cb30-9" title="9"><span class="cf">elif</span> age <span class="op">>=</span> <span class="dv">18</span> :</a>
<a class="sourceLine" id="cb30-10" title="10"> <span class="bu">print</span>(<span class="st">"you are old enough to vote"</span>)</a></code></pre></div>
<blockquote>
<p>note: <br> python actually uses strings for all inputs, you <br> need to cast to the type you want</p>
</blockquote>
<h5 id="a-note-on-casting">A note on casting:</h5>
<p>its pretty important lol</p>
<p>you can cast to a type using:</p>
<div class="sourceCode" id="cb31"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb31-1" title="1">desired_type(thing_being_casted)</a></code></pre></div>
<p>this will change the type of whatever you want</p>
<h5 id="docstrings">docstrings</h5>
<p>these are pretty cool as they can be used for documentation</p>
<div class="sourceCode" id="cb32"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb32-1" title="1"><span class="co">"""this </span></a>
<a class="sourceLine" id="cb32-2" title="2"><span class="co">is a multiline docstring</span></a>
<a class="sourceLine" id="cb32-3" title="3"><span class="co">kek"""</span></a>
<a class="sourceLine" id="cb32-4" title="4"></a>
<a class="sourceLine" id="cb32-5" title="5"><span class="bu">print</span>(<span class="st">"hello"</span>)</a></code></pre></div>
<h4 id="conditionals">Conditionals</h4>
<p>conditionals are pretty cool but are a bit different</p>
<p>in python compared to java.</p>
<p>there is <code>if</code> and <code>else</code> just like in java</p>
</body>
</html>