1.Built-In Types and Data Structures
2.Control Flow
-
if Statements
1
2
3
4
5
6if x < 0:
print("x < 0")
elif x == 0:
print("x==0")
else:
print("x > 0") -
for Statements
1
2
3
4
5
6for w in words[:]:
if len(w) > 6:
0, w) words.insert(
...
words
['defenestrate', 'cat', 'window', 'defenestrate'] -
range() Function
1
2
3
4
5
6
7
8for i in range(3):
print(i)
...
0
1
2
list(range(5))
[0, 1, 2, 3, 4] -
break and continue Statements, and else Clauses on Loops The else Clauses is executed when the loop terminates through exhaustion of the list (with for) or when the condition becomes false (with while), but not when the loop is terminated by a break statement.
1 |
for n in range(2, 5): |
- Defining Functions
1 |
def (n): # write Fibonacci series up to n |
近期评论