wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python test-XIII

Total questions: 54

Worksheet time: 28mins

Name
Class
Date
1.

What is the output of the following piece of code when executed in Python shell?

a=('Check')*3

a)

('Check','Check','Check')

b)

* Operator not valid for tuples

c)

('CheckCheckCheck')

2.

What is the output of the following

aTuple = (10, 20, 30, 40, 50, 60, 70, 80)

print(aTuple[:4:-1])

a)

(30,40,50)

b)

(20,30,40,50)

c)

(80,70,60)

d)

(80,60,40,30)

3.

Choose the correct way to access value 20 from the following tuple

aTuple = ("abc","Apple",[1,0,3,20])

a)

aTuple[1:2][1]

 

b)

aTuple[1:2](1)

 

c)

aTuple[2][3]

d)

 aTuple[1][3]

4.

What is the output of the following

aTuple = ("Yellow", 20.4, "Red")

a, b, c = aTuple

len(b) 

a)

4

b)

 Error

c)

3

5.

predict the output:

t=(20,30,10,23,45,87,11)

sorted(T,reverse=False)

print(t)

a)

Error

b)

(10,11,20,23,30,45,87)

c)

(87,45,30,23,20,11,10)

d)

(20,30,10,23,45,87,11)

6.

Select most suitable code to create a tuple with a single element:

a)

t=('a',)

b)

t=['a']

c)

t=('a')

7.

What will be the output of the following Python code?

t=(1,2,4,3)

t.sorted()

print(t)

a)

(1,2,3,4)

b)

(2,4,3,1)

c)

(4,3,2,1)

d)

(1,2,3,4)

8.

What will be the output of the following Python code?

t1 = (1, 2, 4, 3)

t2 = (1, 2, 3, 4)

t1 ==t2

a)

Error

b)

True

c)

None

d)

False

9.

What will be the output of the following Python code?

my_tuple = (1, 2, 3, 4)

my_tuple+=((5, 6, 7) ,)

print len(my_tuple)

a)

7

b)

5

c)

Error

d)

1

10.

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

a)

print(t.sort())

b)

print(t[3])

c)

print(max(t))

d)

print(len(t))

11.

What will be the output of the following Python code?

tp1=(2,4,3)

tp3=tp1*2

print(tp3)

a)

(4,8,6)

b)

(2,4,3,2,4,3)

c)

(2,2,4,4,3,3)

d)

Error

12.

What will be the output of the following Python code?

tp=()

tp1=tp*2

print(len(tp1)

a)

0

b)

2

c)

1

d)

Error

13.

Which of the following will create a single element tuple?

a)

(1,)

b)

(1)

c)

([1])

d)

None of these

14.

What will be the output of the following Python code?

tp=(5)

tp1=tp*2

print(len(tp1))

a)

0

b)

2

c)

1

d)

Error

15.

What will be the output of the following Python code?

tp=(5,)

tp1=tp*2

print(len(tp1))

a)

0

b)

1

c)

2

d)

Error

16.

Which of the following is a Python tuple?

a)

[1, 2, 3]

b)

(1, 2, 3)

c)

1, 2, 3}

d)

{}

17.

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

a)

print(t[3])

b)

t[3] = 45

c)

print(max(t))

d)

print(len(t))

18.

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:3]

a)

(1, 2)

b)

(1, 2, 4)

c)

(2, 4)

d)

(2, 4, 3)

19.

What will be the output of the following Python code?

>>>t = (1, 2)

>>>2 * t

a)

(1, 2, 1, 2)

b)

[1, 2, 1, 2]

c)

(1, 1, 2, 2)

d)

[1, 1, 2, 2]

20.

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

a)

1

b)

2

c)

5

d)

Error

21.

What is the data type of (1)?

a)

Tuple

b)

Integer

c)

List

d)

Both tuple and integer

22.

If a=(1,2,3,4), a[1:-1] is _________

a)

Error, tuple slicing doesn’t exist

b)

[2,3]

c)

(2,3,4)

d)

(2,3)

23.

What will be the output of the following Python code?

>>> a=(1,2,3,4)

>>> del(a[2])

a)

Now, a=(1,2,4)

b)

Now, a=(1,3,4)

c)

Now a=(3,4)

d)

Error as tuple is immutable

24.

Is the following Python code valid?

>>> a=(1,2,3,4)

>>> del a

a)

No because tuple is immutable

b)

Yes, first element in the tuple is deleted

c)

Yes, the entire tuple is deleted

d)

No, invalid syntax for del method

25.

What type of data is: a=[(1,1),(2,4),(3,9)]?

a)

Array of tuples

b)

List of tuples

c)

Tuples of lists

d)

Invalid type

26.

What is the output of the following piece of code when executed in Python shell?


>>> a=("Check")*3

>>> a



a)

(‘Check’,’Check’,’Check’)

b)

* Operator not valid for tuples

c)

(‘CheckCheckCheck’)

d)

Syntax error

27.

Is the following piece of code valid?


>>> a=(1,2,3,4)

>>> del a

a)

No because tuple is immutable

b)

Yes, the entire tuple is deleted

c)

No, invalid syntax for del method

d)

Yes, first element in the tuple is deleted

28.

What type of data is: a=[(1,1),(2,4),(3,9)]?

a)

Array of tuples

b)

List of tuples

c)

Tuples of lists

d)

Invalid type

29.

Which of the following is true for a tuple?

a)

Tup = 1,2,3

b)

Tup = (""1,"2)

c)

Tup = (1,2,3,4)

d)

None of the above

30.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

31.

Suppose you have the following tuple definition:


t = ('foo', 'bar', 'baz')


Which of the following statements replaces the second element ('bar') with the string 'qux':

a)

t[1] = 'qux'

b)

t(1) = 'qux'

c)

t[1:1] = 'qux'

d)

error

32.

If list=[17,23,41,10] then list.append(32) will result

a)

[32,17,23,41,10]

b)

[17,23,41,10,32]

c)

[10,17,23,32,41]

d)

[41,32,23,17,10]

33.

Suppose list=[12,3,22,"mago","hello"], what is list[-6]

a)

Error

b)

None

c)

mango

d)

12

34.

L_names=['Harsh','Amit','Sahil','Viresh']

min(L_names)

a)

'Harsh'

b)

'Amit'

c)

'Viresh'

d)

None of the above

35.

L_names=['Harsh','Amit','Sahil','Viresh']

L_names.pop()

a)

'Harsh'

b)

'Amit'

c)

'Viresh'

d)

None of the above

36.

If L1=[2,4,8,16], L2=[32,64] what is L1+L2

a)

[2,4,8,16,32,64]

b)

[2,4,8,16][32,64]

c)

[2,4,8,16],[32,64]

d)

None of the above

37.

If L1=[2,4,8,16] What is the result of the following statement

16 in L1

a)

True

b)

False

38.

L=[2,4,8,16,32,64] what is L[:2]

a)

[2,4]

b)

[2,4,8]

c)

2,4

d)

None of the above

39.

T=((1,2,3),(3,4))

what is T[1][1]

a)

4

b)

3

c)

2

d)

1

40.

Which function can be used to convert list to a tuple

a)

tuple

b)

list

c)

to_list

d)

to_tuple

41.

Suppose list1 is [1, 3, 2], What is list1 * 2 ?

a)

[2, 6, 4].

b)

[1, 3, 2, 1, 3]

c)

[1, 3, 2, 1, 3, 2]

d)

[1, 3, 2, 3, 2, 1]

42.

To remove string “hello” from list1, we use which command?

a)

list1.remove(“hello”)

b)

list1.remove(hello)

c)

list.remove(“hello”)

d)

list.remove(hello)

43.

Suppose a tuple T is declared as T=(20,36,34,49), which of the following is incorrect?

a)

print(T[3])

b)

T[3] = 49

c)

print(min(T))

d)

print(T.count(20))

44.

Identify the data type of T:


T = [‘A’, ‘23’, ‘92’, ‘(10,20)’]

a)

List

b)

Dictionary

c)

String

d)

Tuple

45.

What is the output of the code?

a = (33, 55)

a.append(22)

print(a)

a)

33 55 22

b)

33

55

22

c)

33, 55, 22

d)

Error

46.

Tuples in Python are mutable

a)

False

b)

True

47.

How to create a single element tuple

a)

(1,)

b)

(1)

c)

{1}

d)

[1]

e)

tuple([1])

48.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

49.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

50.

What is the output of the code above

a)

(1, '2', 3, 4, 5)

b)

syntax error

c)

(1, 2, 3, 4, 5)

d)

('1', '2', '3', '4', '5')

51.

Which of the following is true

a)

a is assigned a value of 1

b)

b is assigned a value of [2,3]

c)

b is assigned a value of (2,3)

d)

b is assigned a value of 2

52.

What is the output of the program above ?

a)

b is bigger

b)

a is bigger

c)

Syntax error : tuples can't be compared

53.

What is the output of the code above ?

a)

1 4

b)

1

c)

1 None

d)

1 [2,3,4]

e)

1 (2,3,4)

54.

What is the output of the program above ?

a)

True

b)

False