热线电话:13121318867

登录
2018-12-19 阅读量: 676
如何用列表和词典输出多行?

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

# 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)

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子