wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python For All

Total questions: 10

Worksheet time: 11mins

Name
Class
Date
1.

What is the output of the following code :

L = ['a','b','c','d']

print("".join(L))

a)

Error

b)

abcd

c)

None

d)

[‘a’,’b’,’c’,’d’]

2.

What is the output of the following program :

y = 8

z = lambda x : x * y

print (z(6))

a)

48

b)

14

c)

64

d)

None of the above

3.

What is called when a function is defined inside a class?

a)

Module

b)

Class

c)

Another Function

d)

Method

4.

Which of the following is the use of id() function in python?

a)

Every object doesn’t have a unique id

b)

Id returns the identity of the object

c)

All of the mentioned

d)

None of the mentioned

5.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?

a)

[3, 4, 5, 20, 5, 25, 1, 3]

b)

[1, 3, 4, 5, 20, 5, 25]

c)

[1, 3, 3, 4, 5, 5, 20, 25]

d)

[3, 5, 20, 5, 25, 1, 3]

6.

Given a string s = “Welcome”, which of the following code is incorrect?

a)

print s[0]

b)

print s.lower()

c)

s[1] = ‘r’

d)

print s.strip()

7.

Which function overloads the >> operator?

a)

more()

b)

gt()

c)

ge()

d)

None of the above

8.

What is the output of the following program :

i = 0

while i < 3:

print i

i++

print i+1

a)

0 1 2 3 4 5

b)

0 2 1 3 2 4

c)

Error

d)

1 0 2 4 3 5

9.

Which of the following function convert a string to a float in python?

a)

float(x)

b)

long(x [,base] )

c)

int(x [,base])

d)

str(x)

10.

Find the output of the following program:

D = dict()

for x in enumerate(range(2)):

D[x[0]] = x[1]

D[x[1]+7] = x[0]

print(D)

a)

{0: 1, 7: 0, 1: 1, 8: 0}

b)

{1: 1, 7: 2, 0: 1, 8: 1}

c)

KeyError

d)

{0: 0, 7: 0, 1: 1, 8: 1}