Python 程序:打印元组项目
创新互联python教程:

创新互联公司专注于白城企业网站建设,成都响应式网站建设,成都做商城网站。白城网站建设公司,为白城等地区提供建站服务。全流程按需制作网站,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务
编写一个 Python 程序来打印元组中所有项目的列表。我们可以使用 print 函数打印整个元组。在这个例子中,我们声明了字符串和 int 元组并打印它们。
# Print Tuple Items
numTuple = (10, 20, 30, 40, 50)
print("The Tuple Items are ")
print(numTuple )
strTuple = ('C#', 'Java', 'Python', 'C')
print("\nThe String Tuple Items are ")
print(strTuple )在这个 Python 程序中,我们使用 for 循环范围来访问每个元组项。第一个 for 循环从第一个元组项迭代到最后一个,并打印每个元素。第二个循环打印字符串元组中的所有水果。
# Print Tuple Items
numTuple = (10, 20, 30, 40, 50)
print("The Tuple Items are ")
for i in range(len(numTuple)):
print("Tuple Item at %d Position = %d" %(i, numTuple[i]))
print("=========")
fruitsTuple = ('apple', 'orange', 'kiwi', 'grape')
for fruit in fruitsTuple:
print(fruit)The Tuple Items are
Tuple Item at 0 Position = 10
Tuple Item at 1 Position = 20
Tuple Item at 2 Position = 30
Tuple Item at 3 Position = 40
Tuple Item at 4 Position = 50
=========
apple
orange
kiwi
grape 分享题目:Python 程序:打印元组项目
文章分享:http://www.jxjierui.cn/article/dhhdips.html


咨询
建站咨询
