wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Lesson 42 - file related functions

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What will be the output-

f=open('abc','w')

l=['kolkata\n','delhi\n','chennai\n','mumbai\n']

f.write(l)

f.close()

print("written all the elements of list")

a)

written all the elements of list

b)

wrong arguments in write function error

c)

file not available error

d)

Opening wrong file mode error

2.

What is the output of the following program :

print "Hello World"[::-1]

a)

dlroW olleH

b)

Hello Worl

c)

d

d)

Error

3.

What is the output of the following code :

print 9//2

a)

4

b)

4.5

c)

4.0

d)

error

4.

Which of these is not a core data type?

a)

class

b)

list

c)

dictionary

d)

set

5.

What data type is the object below ? L = [1, 23, ‘hello’, 1]

a)

List

b)

Dictionary

c)

tuple

d)

Array

6.

What will be the output of the following code :

print type(type(int))

a)

type 'int'

b)

type 'type'

c)

error

d)

0

7.

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

8.

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

a)

[3, 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, 4, 5, 20, 5, 25, 1, 3]

9.

What is the output of the expression : 3*1**3

a)

27

b)

3

c)

9

d)

1

10.

Which of the following is invalid?

a)

_a = 1

b)

__a = 1

c)

__str__ = 1

d)

none