-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfor_example.py
63 lines (51 loc) · 1.09 KB
/
for_example.py
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
def main() -> None:
"""
for example.
>>> for item in ["Python", "Java", "Google"]:
... print(item)
Python
Java
Google
>>> for char in "Python":
... print(char, end='')
Python
>>> for i in range(0, 6):
... print(i, end='')
012345
>>> for i in range(1, 10, 2):
... print(i, end='')
13579
>>> for i in range(0, 6):
... print(i, end='')
... else:
... print(6, end='')
0123456
>>> for i in range(0, 3):
... for j in range(0, 3):
... print(f"i={i}, j={j}")
i=0, j=0
i=0, j=1
i=0, j=2
i=1, j=0
i=1, j=1
i=1, j=2
i=2, j=0
i=2, j=1
i=2, j=2
>>> for _ in range(0, 100):
... pass
>>> sum(i for i in range(1, 101))
5050
>>> for i in range(1, 6):
... for _ in range(1, i + 1):
... print("*", end='')
... print()
*
**
***
****
*****
"""
if __name__ == "__main__":
from doctest import testmod
testmod()