将下述两个变量的值交换
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)
print(msg1 == msg2)
有存放用户信息的列表如下,分别存放用户的名字、年龄、公司信息userinfo={
'name':'egon',
'age':18,
'company_info':{
'cname':'oldboy',
'addr':{
'country':'China',
'city':'Shanghai',
}
}
要求取出该用户公司所在的城市
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']},
]
取第二个学生的第二个爱好
要求取出三名学生的详细信息分别赋值给三个变量(用一行代码实现)
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
print(a,b,c)