number = 10
guess = int(input("Enter an integer:"))
if guess == number:
print('you guessed it right!')
elif guess > number:
print('you guessed it higher than that!')
else:
print('you guessed it lower than that!')
for i in range(1, 10):
print(i)
else: #执行完for语句之后再执行这条语句
print('The for loop is over!')
#遍历表list
a_list = [1, 3, 5, 7, 9]
for i in a_list:
print(i)
#遍历元组tuple
a_tuple = (2, 4, 6, 8, 10)
for i in a_tuple:
print(i)
#遍历字典
a_dict = {'Tom':3, 'Kim':4, 'Lucy':5}
for ele in a_dict:
print(ele)
print(a_dict[ele])
for key, elem in a_dict.items():
print(key, elem)
来源:oschina
链接:https://my.oschina.net/jugier/blog/4269061