查看字典中所有的key值
以列表返回一个字典所有的键
service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service.keys())

查看字典中所有value值
以列表返回字典中的所有值
service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service.values())

查看字典中key-value值
以列表返回可遍历的(键, 值) 元组数组
service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service.items())

返回指定key的值
service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service['http'])

返回指定键的值,如果值不在字典中返回default值。
service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service.get('http'))

service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service.get('https'))

service = {
'http': 80,
'ftp': 23,
'ssh': 22
}
print(service.get('https',443))

7842

被折叠的 条评论
为什么被折叠?



