一,if语句
1,if条件测试
每条if语句的核心是一个true或false的表达式,这种表达式称为条件测试,如果结果为true,执行跟在后面的语句,如果为false则忽略这些代码。
alien_color =['green','yellow','red']
for color in alien_color:
if color == 'green':
print("玩家获得了5点")
else:
print("玩家获得了10点")
2,使用if语句处理列表
在if中将列表名用在条件表达式中,python将在列表中至少包含一个元素时返回true,列表为空时返回false。
二,字典
1,user={'name':'test111',
'age':'18',
'birth':'1019',
'tel':'13835132323'}
#通过'键'访问字典中的元素
#print(user['age'])
#遍历字典
for key,value in user.items():
print(key +':'+ value)
2,嵌套
在字典中存储列表
在字典中存储字典