2018.9.13作业

s1 = 'alex'
s2 = 'SB'
s1, s2 = s2, s1
print(s1,s2)

msg1 = 'alex say my name is alex,my age is 73,my sex is female'
msg2 = 'alex say my name is alex,my age is 73,my sex is female'
print(msg1 is msg2) pycharm中为True,cmd中为False
print(msg1 == msg2) True

常量是定义完就不变的量,python中未提供常量的定义方法,一般以把全大写的变量作为常量

userinfo = {
'name': 'egon',
'age': 18,
'company_info': {
'cname': 'oldboy',
'addr': {
'country': 'China',
'city': 'Shanghai',
}
}
}
#要求取出该用户公司所在的城市
print(userinfo['company_info']['addr']['city'])

students = [
{'name': 'alex', 'age': 38, 'hobbies': ['play', 'sleep']},
{'name': 'egon', 'age': 18, 'hobbies': ['read', 'sleep']},
{'name': 'wupeiqi', 'age': 58, 'hobbies': ['music', 'read', 'sleep']},
]
取第二个学生的第二个爱好
print(students[1]['hobbies'][1])
要求取出三名学生的详细信息分别赋值给三个变量(用一行代码实现)
a, b, c = students

猜你喜欢

转载自www.cnblogs.com/DariusZhou/p/9642230.html