wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Parithabangal

Total questions: 25

Worksheet time: 17mins

Name
Class
Date
1.

What will be the value of the following Python expression?

print(4 + 3 % 5)

a)

4

b)

7

c)

2

d)

0

2.

What will be the value of x in the following Python expression?

x = int(43.55+2/2)

print(x)

a)

43

b)

44

c)

23

d)

22

3.

What are the values of the following Python expressions?

print(2**(3**2))

print((2**3)**2)

print(2**3**2)

a)

64, 512, 64

b)

64, 64, 64

c)

512, 512, 512

d)

512, 64, 512

4.

What will be the output of the following Python code snippet if x=1?

x<<2

a)

8

b)

1

c)

2

d)

4

5.

What will be the output of the following Python expression if x=15 and y=12?

x & y

a)

b1101

b)

0b1101

c)

12

d)

1101

6.

What will be the output of the following Python code?

True = False

while True:

print(True)

break

a)

True

b)

False

c)

ERROR

d)

none of the mentioned

7.

What will be the output of the following Python code?

i = 0

while i < 3:

print(i)

i += 1

else:

print(0)

a)

0 1 2 3 0

b)

0 1 2 0

c)

0 1 2

d)

error

8.

What will be the output of the following Python code?

x = 123

for i in x:

print(i)

a)

1 2 3

b)

123

c)

error

d)

none of the mentioned

9.

What will be the output of the following Python code snippet?

for i in [1, 2, 3, 4][::-1]:

print(i, end=' ')

a)

1 2 3 4

b)

4 3 2 1

c)

error

d)

none of the mentioned

10.

What will be the output of the following Python code snippet?

x = 2

for i in range(x):

x += 1

print (x)

a)

0 1 2 3

b)

0 1

c)

3 4

d)

error

11.

What will be the output of the following Python code?

print(0xA + 0xB + 0xC)

a)

0xA0xB0xC

b)

Error

c)

0x22

d)

33

12.

To concatenate two strings to a third what statements are applicable?

a)

s3 = s1 . s2

b)

s3 = s1.add(s2)

c)

s3 = s1.__add__(s2)

d)

s3 = s1 * s2

13.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

[2, 33, 222, 14]

b)

Error

c)

25

d)

[25, 14, 222, 33, 2]

14.

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]

15.

What will be the output of the following Python code?

my_tuple = (1, 2, 3, 4)

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

print len(my_tuple)

a)

1

b)

2

c)

5

d)

Error

16.

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

17.

If a={5,6,7}, what happens when a.add(5) is executed?

a)

a={5,5,6,7}

b)

a={5,6,7}

c)

Error as there is no add function for set data type

d)

Error as 5 already exists in the set

18.

What will be the output of the following Python code snippet?

for x in set('pqr'):

print(x*2)

a)

pp qq rr

b)

pqr pqr

c)

ppqqrr

d)

pqrpqr

19.

What will be the output of the following Python code snippet?

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

print(d1 == d2)

a)

True

b)

False

c)

None

d)

Error

20.

What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}

print(a.get(1,4))

a)

1

b)

A

c)

4

d)

Invalid syntax for get method

21.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

a.clear()

print(a)

a)

None

b)

{ None:None, None:None, None:None}

c)

{1:None, 2:None, 3:None}

d)

{ }

22.

What will be the output of the following Python code?

def say(message, times = 1):

print(message * times)

say('Hello')

say('World', 5)

a)

Hello WorldWorldWorldWorldWorld

b)

Hello World 5

c)

Hello World,World,World,World,World

d)

Hello HelloHelloHelloHelloHello

23.

Which are the advantages of functions in python?

a)

Reducing duplication of code

b)

Decomposing complex problems into simpler pieces

c)

Improving clarity of the code

d)

All of the mentioned

24.

What will be the output of the following Python code?

def test(i,j):

if(i==0):

return j

else:

return test(i-1,i+j)

print(test(4,7))

a)

13

b)

7

c)

Infinite loop

d)

17

25.

Draw your best friend and mention their name