詹惠儿

2018-12-19   阅读量: 485

数据分析师 Python数据分析

如何用列表和词典输出多行?

扫码加入数据分析学习群

使用列表:列表就像使用方括号创建的项目数组。它们与数组不同,因为它们可以包含不同类型的项目。列表与元组不同,因为它们是可变的。

# A Python program to to return multiple

# values from a method using list

# This function returns a list

def fun():

str = "geeksforgeeks"

x = 20

return [str, x];

# Driver code to test above method

list = fun()

print(list)

使用词典:词典类似于其他语言中的哈希或地图

# A Python program to to return multiple

# values from a method using dictionary

# This function returns a dictionary

def fun():

d = dict();

d['str'] = "GeeksforGeeks"

d['x'] = 20

return d

# Driver code to test above method

d = fun()

print(d)

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 3 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子