You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -32,11 +34,11 @@ For beginners we recommend using Microsoft's open-source [VSCode editor](https:/
32
34
33
35
Some extensions we recommend for Python development with VSCode include:
34
36
35
-
-[Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) by Microsoft: Enables Python language support in VSCode and test tools.
36
-
-[Kite](https://marketplace.visualstudio.com/items?itemName=kiteco.kite): A coding assistant that aids with autocompletion and shows docstrings.
37
-
-[Wolf](https://marketplace.visualstudio.com/items?itemName=traBpUkciP.wolf): Live Python scratchpad
38
-
-[Sort Lines](https://tyriar.gallerycdn.vsassets.io/extensions/tyriar/sort-lines/1.9.0/1573941482699/Microsoft.VisualStudio.Services.Icons.Small): Automatically sort lines of long dictionary keys.
39
-
-[Guides](https://marketplace.visualstudio.com/items?itemName=spywhere.guides): Adds extra indentation guides.
37
+
-[Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) by Microsoft: Enables Python language support in VSCode and test tools.
38
+
-[Kite](https://marketplace.visualstudio.com/items?itemName=kiteco.kite): A coding assistant that aids with autocompletion and shows docstrings.
39
+
-[Wolf](https://marketplace.visualstudio.com/items?itemName=traBpUkciP.wolf): Live Python scratchpad
40
+
-[Sort Lines](https://tyriar.gallerycdn.vsassets.io/extensions/tyriar/sort-lines/1.9.0/1573941482699/Microsoft.VisualStudio.Services.Icons.Small): Automatically sort lines of long dictionary keys.
41
+
-[Guides](https://marketplace.visualstudio.com/items?itemName=spywhere.guides): Adds extra indentation guides.
40
42
41
43
## Downloading Packages
42
44
@@ -130,7 +132,7 @@ Accessing values in dictionaries happens a little differently, since they're all
130
132
131
133
#### Lists
132
134
133
-
Lists do exactly what the name suggests. They let you store multiple variables in them, and access them via *indices* later on. Indices begin from 0 - being the first element, and progress upwards. Let's take a look at an example:
135
+
Lists do exactly what the name suggests. They let you store multiple variables in them, and access them via _indices_ later on. Indices begin from 0 - being the first element, and progress upwards. Let's take a look at an example:
134
136
135
137
```python
136
138
my_list = [1, 1.5, "test", True]
@@ -190,62 +192,71 @@ print(multiply(5, 2))
190
192
191
193
Lambdas automatically return the value they're assigned to, so the `return` keyword can be omitted.
192
194
193
-
### Loops and If statements
195
+
### Loops and `if` Statements
196
+
197
+
#### `while` Loops
194
198
195
-
#### While loops
196
199
While loops work by running a certain piece of code while a given statement is true. So for example if you wanted to print all numbers up to 10 with a while statement, you would do this:
200
+
197
201
```py
198
202
i =0
199
203
while i<10:
200
204
print(i)
201
205
i +=1# increment the counter
202
206
```
207
+
203
208
A trace table for this can be seen here:
209
+
204
210
```markdown
205
-
| Iteration | I | While | Output |
206
-
|-----------|----|-------|-----------|
207
-
| 1 | 0 | True | 0 |
208
-
| 2 | 1 | True | 1 |
209
-
| 3 | 2 | True | 2 |
210
-
| 4 | 3 | True | 3 |
211
-
| 5 | 4 | True | 4 |
212
-
| 6 | 5 | True | 5 |
213
-
| 7 | 6 | True | 6 |
214
-
| 8 | 7 | True | 7 |
215
-
| 9 | 8 | True | 8 |
216
-
| 10 | 9 | True | 9 |
217
-
| 11 | 10 | False | No output |
211
+
| Iteration | I | While | Output |
212
+
|--------- | --- | ----- | ---------|
213
+
| 1 | 0 | True | 0 |
214
+
| 2 | 1 | True | 1 |
215
+
| 3 | 2 | True | 2 |
216
+
| 4 | 3 | True | 3 |
217
+
| 5 | 4 | True | 4 |
218
+
| 6 | 5 | True | 5 |
219
+
| 7 | 6 | True | 6 |
220
+
| 8 | 7 | True | 7 |
221
+
| 9 | 8 | True | 8 |
222
+
| 10 | 9 | True | 9 |
223
+
| 11 | 10 | False | No output |
218
224
```
219
-
#### For loops
225
+
226
+
#### `for` Loops
227
+
220
228
For loops are similar to while loops however they work with ranges. These ranges can be different things, you can have ranges between numbers but similarly you can have ranges on strings. We will replicate the numbers between 1 and 10 with a for loop.
229
+
221
230
```py
222
231
for i inrange(0,10):
223
232
print(i)
224
233
```
234
+
225
235
As you can see this is much more efficient, you do not need to increment the variable manually or even initialise it, the for loop does this itself. As stated above you can also do this on strings so i will show this below too:
236
+
226
237
```py
227
238
my_str ="hello world"
228
239
for i in my_str:
229
240
print(i)
230
-
"""
231
-
Output:
232
-
h
233
-
e
234
-
l
235
-
l
236
-
o
237
-
238
-
w
239
-
o
240
-
r
241
-
l
242
-
d
243
-
"""
241
+
>>> h
242
+
>>> e
243
+
>>> l
244
+
>>> l
245
+
>>> o
246
+
>>>
247
+
>>> w
248
+
>>> o
249
+
>>> r
250
+
>>> l
251
+
>>> d
244
252
```
245
-
As you can see it goes over each character individually, in an iterative process.
246
253
247
-
#### If / else/ elif statements
254
+
As you can see it goes over each character individually, in an iterative process.
255
+
256
+
#### `if` / `else`/ `elif` Statements
257
+
248
258
If statements are a fundamental concept in the majority of programming languages and python is no different, this is used to check if a given condition is true. If it is then it will execute the code it is supplied if not it will go to through elif until one is true (if supplied) if none are true then it will go to the else statement. An example of this will be:
259
+
249
260
```py
250
261
age =int(input("Enter your age"))
251
262
if age <18:
@@ -255,14 +266,13 @@ elif age > 18:
255
266
else:
256
267
print('Please provide ID, 18 year olds must be checked')
257
268
258
-
"""
259
269
>>> Enter your age
260
-
>18
261
-
Please provide ID, 18 year olds must be checked
270
+
>18
271
+
>>> Please provide ID, 18 year olds must be checked
0 commit comments