wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Tuples Quiz

Total questions: 15

Worksheet time: 10mins

Name
Class
Date
1.

下面哪一个是元组?

a)

thistuple = 'apple, banana, cherry'

b)

thistuple = {'apple', 'banana', 'cherry'}

c)

thistuple = ('apple', 'banana', 'cherry')

d)

thistuple = ['apple', 'banana', 'cherry']

2.

下面哪个代码可以在python里面表示一个元组?

a)

tuple = '1, 2, 3'

b)

tuple = {1, 2, 3}

c)

tuple = [1, 2, 3]

d)

tuple = (1, 2, 3)

3.

以下哪项不是元组的特征?

a)

元组是有序集合。

b)

元组可以包含重复元素。

c)

元组在创建后可以修改。

d)

元组是不可变的。

4.

哪种数据结构用于将多个项目存储在一个变量中?

a)

元组

b)

字符串

c)

整数

d)

浮点数

5.

使用正确的语法打印水果元组中的元素数量

fruits = ("apple", "banana", "cherry")

print( (a)   )

6.

您可以通过引用索引号来访问元组中的元素,那么第一个元素的索引号是多少?

a)

1

b)

0

c)

-1

7.

完善对应的语法,使代码可以输出元组fruits里面的第一个元素

fruits = ("apple", "banana", "cherry")

print( (a)   )

8.

使用带负号的索引输出元组fruits里面的最后一个元素

fruits = ("apple", "banana", "cherry")

print( (a)   )

9.

使用一个范围索引,输出元组fruits里面的第3,第4,第5个元素

fruits = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")

print(fruits[ (a)   ])

10.

一般情况下您无法更改元组的项,但有解决方法。以下哪项建议可行?

a)

将元组转换为列表,更改项目,再转换回元组。

b)

将元组转换为集合,更改项目,再转换回元组。

c)

将元组转换为字典,更改项目,再转换回元组。

11.

删除元组的正确语法是什么?

a)

delete mytuple

b)

mytuple.delete()

c)

del mytuple

12.

你可以将一个元组添加到一个现有元组中

a)

b)

13.

如何把tuple1和tuple2合并成一个新的元组tuple3

a)

tuple3 = join(tuple1, tuple2)

b)

tuple3 = tuple1 + tuple2

c)

tuple3 = [tuple1, tuple2]

14.

下面哪个方法可以将元组(1,2,3)转换为元组(1,2,3,1,2,3)


a)

tuple1 = (1,2,3)
tuple1 = tuple1 * 2

b)

tuple1 = (1,2,3)
tuple1.double()

c)

tuple1 = (1,2,3)
tuple1.add(_self)

15.

在下面代码的情况下:

tuple1 = ('a', 'b' , 'c')
tuple2 = (1, 2, 3)
tuple3 = tuple2 + tuple1

tuple3的值应该为

a)

('a', 'b', 'c', 1, 2, 3)

b)

1, 2, 3, 'a', 'b', 'c')

c)

('a', 1, 'b', 2, 'c', 3)