Font size
WorksheetsPython Tuples Quiz
Total questions: 15
Worksheet time: 10mins
下面哪一个是元组?
thistuple = 'apple, banana, cherry'
thistuple = {'apple', 'banana', 'cherry'}
thistuple = ('apple', 'banana', 'cherry')
thistuple = ['apple', 'banana', 'cherry']
下面哪个代码可以在python里面表示一个元组?
tuple = '1, 2, 3'
tuple = {1, 2, 3}
tuple = [1, 2, 3]
tuple = (1, 2, 3)
以下哪项不是元组的特征?
元组是有序集合。
元组可以包含重复元素。
元组在创建后可以修改。
元组是不可变的。
哪种数据结构用于将多个项目存储在一个变量中?
元组
字符串
整数
浮点数
使用正确的语法打印水果元组中的元素数量
fruits = ("apple", "banana", "cherry")
print( (a) )
您可以通过引用索引号来访问元组中的元素,那么第一个元素的索引号是多少?
1
0
-1
完善对应的语法,使代码可以输出元组fruits里面的第一个元素
fruits = ("apple", "banana", "cherry")
print( (a) )
使用带负号的索引输出元组fruits里面的最后一个元素
fruits = ("apple", "banana", "cherry")
print( (a) )
使用一个范围索引,输出元组fruits里面的第3,第4,第5个元素
fruits = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(fruits[ (a) ])
一般情况下您无法更改元组的项,但有解决方法。以下哪项建议可行?
将元组转换为列表,更改项目,再转换回元组。
将元组转换为集合,更改项目,再转换回元组。
将元组转换为字典,更改项目,再转换回元组。
删除元组的正确语法是什么?
delete mytuple
mytuple.delete()
del mytuple
你可以将一个元组添加到一个现有元组中
对
错
如何把tuple1和tuple2合并成一个新的元组tuple3
tuple3 = join(tuple1, tuple2)
tuple3 = tuple1 + tuple2
tuple3 = [tuple1, tuple2]
下面哪个方法可以将元组(1,2,3)转换为元组(1,2,3,1,2,3)
tuple1 = (1,2,3)
tuple1 = tuple1 * 2
tuple1 = (1,2,3)
tuple1.double()
tuple1 = (1,2,3)
tuple1.add(_self)
在下面代码的情况下:
tuple1 = ('a', 'b' , 'c')
tuple2 = (1, 2, 3)
tuple3 = tuple2 + tuple1
tuple3的值应该为
('a', 'b', 'c', 1, 2, 3)
1, 2, 3, 'a', 'b', 'c')
('a', 1, 'b', 2, 'c', 3)
