#字典
alien_0={‘color’:‘green’,‘points’:5}
print(alien_0[‘color’])
alien_0[‘x_postion’]=0
alien_0[‘y_postion’]=25#添加键-值对
print(alien_0)
alien_1={}
alien_1[‘color’]=‘green’
alien_1[‘points’]=5
print(alien_1)
del alien_1[‘points’]
print(alien_1)#删除键值对
favorite_language={
‘jen’:‘python’,
‘sarach’:‘c’,
‘edward’:‘ruby’,
‘phil’:‘python’
}
print(favorite_language)
user_0={‘user_name’:‘efermi’,‘frist’:‘enrico’,‘last’:‘fermi’}
for key,value in user_0.items():#items()遍历键-值
print("\nkey:"+key)
print("\nkey:"+key)
for key in favorite_language.keys():#遍历键
print(key.title())
for key in sorted(favorite_language.keys()):#按顺序遍历
print(key.title())
for key in favorite_language.values():#遍历值
print(key.title())
alien_2={‘color’:‘red’,‘points’:15}
aliens=[alien_0,alien_1,alien_2]
for alien in aliens:
print(alien)
pizza={‘crust’:‘thick’,‘toppings’:[‘mushrooms’,‘extra cheese’]}#在字典中套列表
#name=input(“please enter your name: “)#input()程序暂停运行,等待用户输入
#print(“hello”+name+”!”)
age=input(“How old are you?: “)
print(age)
message=””
while message !=‘quit’:
message=input(“prompt”)
print(message)
python3day
最新推荐文章于 2022-04-02 13:30:57 发布