mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
Added some python loops
This commit is contained in:
1 parent
0b9d86e1a0
commit
0dff3f0fe9
1 file changed
+16
@@ -713,6 +713,22 @@ for i in range(4, 10, 2):
|
||||
```
|
||||
|
||||
|
||||
### With zip()
|
||||
```python
|
||||
name = ['Pete', 'John', 'Elizabeth']
|
||||
age = [6, 23, 44]
|
||||
for n, a in zip(name, age):
|
||||
print('%s is %d years old' %(n, a))
|
||||
```
|
||||
|
||||
### List Comprehension {.col-span-2}
|
||||
```python
|
||||
result = [x**2 for x in range(10) if x % 2 == 0]
|
||||
|
||||
print(result)
|
||||
# [0, 4, 16, 36, 64]
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user