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)


暂无数据
推荐帖子
0条评论
0条评论
0条评论