coding=gbk
coding:utf-8!
6-1人
friend1 = {‘first_name’: ‘yao’, ‘last_name’: ‘hu’, ‘age’: 30, ‘city’:
‘shenzhen’,
}
print(friend1)
print(friend1[‘first_name’] + ', ’ + friend1[‘last_name’] + ', ’ +
str(friend1[‘age’]) + ', ’ + friend1[‘city’])
6-2喜欢的数字
favorite_nums = {‘john’: 2,
‘sarah’: 8,
‘nancy’: 9,
‘jenny’: 1,
‘josh’: 6,
}
print("\n")
print(favorite_nums)
for i, j in favorite_nums.items():
print(i.title() + "'s favorite number is " + str(j) + “.”)
注意items后的括号
print("\n")
6-3词汇表
dicts = {‘a’: ‘apple’, ‘b’: ‘boy’,
‘c’: ‘cat’, ‘d’: ‘dog’,
}
for key, value in dicts.items():
print(key + ": " + value)
为什么不能decode中文??? # 要在最前面加一个coding=gbk
print("\n")