Python学习日志 - 6.字典(习题解答)

本文通过几个简单的Python代码片段展示了如何使用字典来存储和检索数据。包括个人基本信息、喜欢的数字、词汇表解释、河流信息等示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#6-1 人
people = {
"first_name" : "Bill",
"last_name" : "Gate",
"age" : 34,
"city" : "Los Angeles"
}

#6-2 喜欢的数字
numbers = {
"bill" : 2,
"john" : 3,
"mary" : 4,
"nick" : 5,
"david" : 6
}
for key in numbers.keys():
print( " {0} loves number {1} ".format(key, numbers[key]))

#6-3&4 词汇表
opcode = {
" \\ n" : "out put a enter key",
" \\ r" : "move the cur to the beginning of the line",
" \\ t" : "out put a tap key",
"main" : "main function of a c progrem",
"int" : "data type refer to integer"
}
for key in opcode.keys():
print( " {0} : {1} ".format(key, opcode[key]))

#6-5 河流
river = {
"nile" : "egypt",
"Changjiang" : "china",
"HuangHe" : "china"
}
for key in river.keys():
print( "The {0} runs through {1} ".format(key, river[key]))
for key in river.keys():
print(key)
for key in river.keys():
print(river[key])

#6-7
people1 = {
"first_name": "July",
"last_name": "Gate",
"age": 34,
"city": "Los Angeles"
}
people2 = {
"first_name": "Lucy",
"last_name": "Gate",
"age": 34,
"city": "Los Angeles"
}
people3 = {
"first_name": "Bill",
"last_name": "Gate",
"age": 34,
"city": "Los Angeles"
}

list1 = [people1, people2, people3]
for peo in list1:
print(peo[ 'first_name'] + " " + peo[ 'last_name'])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值