编程语言
首页 > 编程语言> > doraemon的python 字典

doraemon的python 字典

作者:互联网

day05数据类型

今日回顾

#练习题
name = [11,22,33,44]
v = "*".join(name)  #错误 join后面加的内容必须是字符串
name = ['11','22','33','44']
v = "*".join(name)   #正确

 

 

字典

帮助用户去表示一个事物的信息(事物的多个属性)

 

请表示刘伟达的信息,年龄18,性别:男,爱好:同桌

name = '刘伟达'
age = 18
gender = '男'
hobby = '同桌'

data = "'刘伟达','18','男','同桌'"

data =[ "'刘伟达','18','男','同桌'"]

 

基本格式

info = {"name":"刘伟达","age":18,"gender":"男","hobby":"同桌"}
userinfo = {'username':'alex','password':'oldboy'}

user = input('请输入你的账号:')
pwd = input('请输入你的密码')
if user == username and pwd == password:
   print('登录成功')

 

 

1.独有功能

info = {"name":"刘伟达","age":18,"gender":"男","hobby":"同桌"}

info = {"name":"刘伟达","age":18,"gender":"男","hobby":"同桌"}
info.keys()  #获取字典中所有的键
info.values()  #获取字典中的所有值
info.item()  #获取字典中的所有键值对

# for item in info.keys():
#     print(item)
# for item in info.values():
#     print(item)

for v1,v2 in info.items():
   print(v1,v2)

 

2.公共功能

重点

标签:info,伟达,name,python,18,同桌,doraemon,hobby,字典
来源: https://www.cnblogs.com/doraemon548542/p/11133342.html