Update README.md
This commit is contained in:
parent
4ad87a26af
commit
495dcc6705
@ -8,31 +8,31 @@ Get ready for FizzBuzz, again!
|
|||||||
For loop syntax in Python is slightly different.
|
For loop syntax in Python is slightly different.
|
||||||
The 'for in' pattern is still available in Python:
|
The 'for in' pattern is still available in Python:
|
||||||
```
|
```
|
||||||
>>> for thing in list:
|
for thing in list:
|
||||||
... print(thing)
|
print(thing)
|
||||||
```
|
```
|
||||||
Python also has what's known as a range:
|
Python also has what's known as a range:
|
||||||
```
|
```
|
||||||
>>> lst = ['a', 'b', 'c']
|
lst = ['a', 'b', 'c']
|
||||||
>>> for i in range(len(lst)):
|
for i in range(len(lst)):
|
||||||
... print(i)
|
print(i)
|
||||||
0
|
0
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
```
|
```
|
||||||
If we wanted to print the element in the list, rather than the index, we could do it like this:
|
If we wanted to print the element in the list, rather than the index, we could do it like this:
|
||||||
```
|
```
|
||||||
>>> lst = ['a', 'b', 'c']
|
lst = ['a', 'b', 'c']
|
||||||
>>> for i in range(len(lst)):
|
for i in range(len(lst)):
|
||||||
... print(lst[i])
|
print(lst[i])
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
c
|
c
|
||||||
```
|
```
|
||||||
With range, you have the option to choose the start and stop points, as well as increment.
|
With range, you have the option to choose the start and stop points, as well as increment.
|
||||||
```
|
```
|
||||||
>>> for i in range(2, 10, 2):
|
for i in range(2, 10, 2):
|
||||||
... print(i)
|
print(i)
|
||||||
2
|
2
|
||||||
4
|
4
|
||||||
6
|
6
|
||||||
|
Loading…
x
Reference in New Issue
Block a user