Python学习笔记04-字典和用户输入和 while 循环
2017-06-04 10:47
716 查看
一个简单的字典
alien = {'color': 'green', 'points': 5} print(alien['color']) print(alien['points']) green 5
增加字典
alien['animal'] = 'dog'
创建一个空字典
alien_0 = {} alien_0['color'] = 'green' alien_0['points'] = 5 print(alien_0) {'color': 'green', 'points': 5} 修改 alien_0['color'] = 'yellow'
删除字典
del alien_0[‘color’]取出字典
user_0 = { 'username': 'efermi', 'first': 'enrico', 'last': 'fermi', } for key, value in user_0.items(): print("\nKey: " + key) print("Value: " + value)
取出键
for key in user_0.keys(): print("\nKey: " + key)
取出值
for value in user_0.values(): print("Value: " + value)
在字典中存储字典
users = { 'aeinstein': { 'first': 'albert', 'last': 'einstein', 'location': 'princeton', }, 'mcurie': { 'first': 'marie', 'last': 'curie', 'location': 'paris', }, } for username, user_info in users.items(): print("\nUsername: " + username) full_name = user_info['first'] + " " + user_info['last'] location = user_info['location'] print("\tFull name: " + full_name.title()) print("\tLocation: " + location.title())
函数 input() 的工作原理
message = input("Tell me something, and I will repeat it back to you: ") prompt += "\nWhat is your first name? " print(message)
使用 while 循环
current_number = 1 while current_number <= 5: print(current_number) current_number += 1 使用 break 退出循环 在循环中使用 continue
相关文章推荐
- Python学习笔记(10)- 用户输入和while循环
- python 学习笔记之(四)while循环处理列表和字典
- Python3学习笔记【基础3--list,tuple,if条件判断,for/while循环,dict字典,set集合】
- 【day 5】python编程:从入门到实践学习笔记-用户输入和while循环(末答案)
- Python学习---用户输入和while循环
- Python学习第四周第一次作业——用户输入和while循环
- python学习第七章用户输入和While循环部分课后练习自己尝试的代码
- python学习——用户输入和while循环
- Python学习日志 - 7.用户输入和while循环(习题解答)
- Python学习笔记——输入语句和while循环
- Python_用户输入和while循环
- Python学习笔记(3)用户输入&函数
- 【Python学习笔记】for和while循环语句
- 学习笔记☞ python 基础(python3)【三】(转义字符,字符串,while循环,break语句,列表)
- 【Hello Python World】Week 4(1):用户输入和while循环
- Python学习笔记之while循环
- Python编程:从入门到实践读书笔记-7 用户输入和while循环
- 用户输入和while循环(python)
- Python学习笔记——while循环优化脚本(二)
- python笔记-007-★输入和while循环