1. if 语句
demo
if condition:
do something
elif other_condition:
do something
else:
do something
code
# if statement example
number = 59
guess = int(input("Enter an integer: "))
# print("guess is: "+str(guess))
if guess == number:
print("you are right")
elif guess < number:
print("the number is higher than that")
else:
print("the number is lower than that")
print("done")
2. for语句
code
# for loop example
for i in range(1,10):
print(i)
else:
print("for loop is over")
a_list = [1,3,5,7,9]
for i in a_list:
print(i)
a_tuple = (2,4,6,8,10)
for i in a_tuple:
print(i)
a_dict = {"xiao":1,"shu":2,"yi":3}
for ele in a_dict:
print(ele)
print(a_dict[ele])
for key,value in a_dict.items():
print(key,value)
console
1
2
3
4
5
6
7
8
9
for loop is over
1
3
5
7
9
2
4
6
8
10
yi
3
shu
2
xiao
1
yi 3
shu 2
xiao 1