python

使用字典

2018-10-30  本文已影响4人  庵下桃花仙
# 6-1
people = {'first_name': 'Liu', 'last_name': 'yan', 'age': 25, 'city': 'henan'}
print(people['first_name'])
print(people['last_name'])
print(people['age'])
print(people['city'])

# 6-2
luck_numbers = {
    'wangyangming': 6,
    'zhudi': 2,
    'linghuchong': 1,
    'xiaoyao': 8,
    'yaoguangxiao': 9,
    }

print("wangyangming like " + str(luck_numbers['wangyangming']) + '!')
print("zhudi like " + str(luck_numbers['zhudi']) + '!')
print("linghuchong like " + str(luck_numbers['linghuchong']) + '!')
print("xiaoyao like " + str(luck_numbers['xiaoyao']) + '!')
print("yaoguangxiao like " + str(luck_numbers['yaoguangxiao']) + '!')

# 6-3
vocabularys = {'list': '列表',
               'int': '整数',
               'float': '小数',
               'if': '条件语句',
               'print': '打印'
               }

print("\nlist: " + vocabularys['list'])
print("\nint: " + vocabularys['int'])
print("\nfloat: " + vocabularys['float'])
print("\nif: " + vocabularys['if'])
print("\nprint: " + vocabularys['print'])
Liu
yan
25
henan
wangyangming like 6!
zhudi like 2!
linghuchong like 1!
xiaoyao like 8!
yaoguangxiao like 9!

list: 列表

int: 整数

float: 小数

if: 条件语句

print: 打印
上一篇 下一篇

猜你喜欢

热点阅读