wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Mix Quiz

Total questions: 64

Worksheet time: 32mins

Name
Class
Date
1.

What will the following code result in?

a)

True

[9, 7, 5, 3, 1]

b)

False

[9, 7, 5, 3, 1]

c)

True

[1, 3, 5, 7, 9]

d)

None of the above

2.

Predict the output:

a)

1

2

[13, 18, 11, 16, 13, 18, 13, 2]

b)

0

2

[13, 18, 11, 16, 13, 18, 13, 3]

c)

5

2

[13, 18, 11, 16, 13, 18, 13, 3]

d)

1

2

[13, 18, 11, 16, 13, 18, 13, 3]

3.

Given two lists, which of the following statements will cause an error?

a)

L1==L2

b)

L1.upper()

c)

L1[3].upper()

d)

L2[1][1].upper()

4.

Out of the following, what is correct syntax to copy one list into another?

a)

listA=listB[]

b)

listA=listB[:]

c)

listA=listB[]()

d)

listA=list(listB)

5.

What is the output when we execute list("hello")?

a)

['h','e','l','l','o']

b)

['hello']

c)

['llo']

d)

['olleh']

6.

What gets printed?

a)

H

b)

a

c)

Hasan

d)

Dia

7.

Which of the following statements will create a tuple?

a)

tp1=("a","b")

b)

tp1[2]=("a","b")

c)

tp1=(3)*3

d)

None of these

8.

What will be the output of following Python code?

a)

(15,11,16,12)

b)

(15,11,17,16)

c)

(15,11,17,16,12)

d)

Error

9.

Which of the following options will not result in an error when performed on types in Python where tp=(5,2,7,0,3)?

a)

tp[1]=2

b)

tp.append(2)

c)

tp1=tp+tp

d)

tp.sum()

10.

What is the length of the tuple t=(((('a',1),'b','c'),'d',2),'e',3) ?

a)

1

b)

2

c)

3

d)

4

11.

What will be stored in variables 'a' after following statements?

perc=(88,85,80,88,83,86)

a=perc[2:-2]

a)

(80,88)

b)

(80,88,83)

c)

(88,80)

d)

(83,88,80)

12.

Carefully read the given code fragments and figure out the errors that the code may produce.

a)

t5=t3*(3)

b)

t4=t3*3

c)

t3=(6,7)

d)

t6=t3*(3,)

13.

Predict the output :-

a)

3

2

False

3

2

b)

2

2

False

3

3

c)

3

3

False

2

2

d)

2

3

False

2

3

14.

What will be the output of the following code snippet?

Tup1=((1,2),)*7

print(len(Tup1[3:8]))

a)

2

b)

3

c)

4

d)

5

15.

Find the output generated by the code fragment :

plane=("Passengers","Luggage")

plane[1]="Snakes"

a)

plane=("Passengers","Snakes")

b)

plane=("Passengers","Snakes","Luggage")

c)

plane=("Snakes","Passengers","Luggage")

d)

Error

16.

What is the output of the following code?

a)

[0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]

b)

[4, 8, 16, 20, 28, 32, 40, 44]

c)

[0, 12, 24, 36, 48]

d)

None of the above

17.

Find the error :

L1=[1,11,21,31]

An=L1.remove(41)

a)

(a) Value error : 41 not in list

b)

(b) remove() doesn't return any value

c)

(c) remove() function is not applicable on lists

d)

(d) both (a) & (b)

18.

Given a list L1=[3,4.5,12,25.7,[2,1,0,5],88], which function can change the list to [3,4.5,12,25.7,88]?

a)

del L1[4]

b)

L1.pop(4)

c)

L1.pop(-2)

d)

All the above

19.

Write the output of the following code:

>>> L=[“Amit”,”Anita”,”Zee”,”Longest Word”,123]

>>> print(max(L))

a)

Longest Word

b)

Zee

c)

Amit

d)

Error

20.

Write the output of the following code :

>>>L=[1,2,3,4,5,[6,7,8]]

>>>print(L[5])

a)

[6, 7, 8]

b)

6, 7, 8

c)

Error

d)

6

21.

(a)   is smallest individual unit in a program.

22.

Choose the INVALID identifiers from the following

a)

NUmbEr1

b)

1NUMBer

c)

A_B

d)

A&B

23.

________ are data items that have a fixed value

a)

Tokens

b)

Literals

c)

Keyword

d)

Operators

24.

Examples of String Literals

a)

"ABC1273"

b)

nfjdlsj@@$

c)

12638

d)

'7e920938'

25.

Escape sequence is represented by a ____ followed by one or more characters

a)

Front slash

b)

Double Quote

c)

Single Quote

d)

Back Slash

26.

Size of the string "Ant Man"

(a)  

27.

str="Red\

block\

a"

Size of str is 11. True/False ?

a)

True

b)

False

28.

Select the valid Octal integer literals

a)

0836

b)

7976

c)

07362

d)

0x1726

29.

An escape sequence represents how many characters ?

"\t"

a)

3

b)

2

c)

1

d)

4

30.

(a)   is a special literal used to indicate something has not yet been created. It also indicates the end of lists in Python.

31.

Which of the following is a Boolean literal ?

a)

True

b)

false

c)

False

d)

true

32.

+, /, * are example of which token ?

This token triggers some computation

(a)  

33.

What will be the output-

f=open('abc.txt','a')

text="xyz"

f.write(text)

f.close()

a)

Writing into the file without erasing old content

b)

Writing into the file by erasing old content

c)

reading from the file without erasing old content

d)

reading from the file by erasing old content

34.

Mode in the following program to open file for writing in a mode where new data will be added at the end of old data

file =open("poem.txt","__")

a)

r

b)

w

c)

a

d)

r+

35.

Choose the correct statement to close a file stream named myfile:

a)

myfile.terminate()

b)

myfile.end()

c)

myfile.close()

d)

myfile.remove()

36.

Fill in the blank with appropriate statement.

(a)  

37.

Write the appropriate statement in the blank.

(a)  

38.

Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing.

a)

file =open("Record.dat","wb")

b)

file =open("Record.dat","rb")

c)

file =open("Record.dat","ab")

d)

file =open("Record.dat","rb+")

39.

Which function read single line at a time?

a)

read()

b)

read(n)

c)

readline()

d)

readlines()

40.

Which file is not binary file?

a)

student.mp4

b)

student.jpeg

c)

student.csv

d)

student.exe

41.

Where files are store permanently?

a)

RAM

b)

Hard Disk

c)

Cache memory

d)

None of these

42.

Which function is used to write multiple lines in text file?

a)

write()

b)

writelines()

c)

lines()

d)

print()

43.
Appending to a file means adding extra data into the file.
a)
True
b)
False
44.

Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing ?

a)

file =open("Record.dat","wb")

b)

file =open("Record.dat","rb")

c)

file =open("Record.dat","ab")

d)

file =open("Record.dat","rb+")

45.

Q.2 Which of the following statements are not true regarding the opening modes of a file?

a)

When you open a file for reading, if the file does not exist, an error occurs.

b)

When you open a file for writing, if the file does not exist, an error occurs

c)

When you open a file for writing, if the file does not exist, a new file is created.

d)

When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

46.

Q.3 Which module is used to work with binary files?

a)

CSV module

b)

pickle module

c)

math module

d)

binary module

47.

Q.5 'try' block is used to

a)

execute a code

b)

through the exceptions

c)

to try some random code

d)

to give errors

48.

Function used to write data in binary format

a)

write()

b)

output()

c)

load()

d)

dump()

49.
Which of the following is not a method of opening files?
a)
Replace
b)
Append
c)
Write
d)
Read
50.
What is the data type of data read from a file?
a)
String
b)
Integer
c)
Real
d)
Boolean
51.
Reading from a file often involves using...
a)
A loop
b)
An condition
c)
Comments
52.

What is the use of “a” in file handling?

a)

Read

b)

Write

c)

Append

d)

None of the mentioned

53.
Which keyword is use for function?
a)
define
b)
fun
c)
def
d)
function
54.
Which of the following items are present in the function header?
a)
function name
b)
parameter list
c)
return value
d)
Both A and B
55.
What is called when a function is defined inside a class?
a)
class
b)
function
c)
method
d)
module
56.
If return statement is not used inside the function, the function will return:
a)
None
b)
0
c)
Null
d)
Arbitary value
57.
Which of the following is the use of function in python?
a)
Functions are reusable pieces of programs
b)
Functions don’t provide better modularity for your application
c)
you can’t also create your own functions
d)
All of the mentioned
58.
In which part of memory does the system stores the parameter and local variables of funtion call?
a)
heap
b)
stack
c)
Uninitialized data segment
d)
None of the above
59.
How is a function declared in Python?
a)
def function function_name():
b)
declare function function_name():
c)
def function_name():
d)
declare function_name():
60.
Which one of the following is the correct way of calling a function?
a)
function_name()
b)
call function_name()
c)
ret function_name()
d)
function function_name()
61.
What will be the output of the following Python code? def sayHello():<br /> print('Hello World!') <br />sayHello() <br />sayHello()
a)
Hello World! Hello World!
b)
Hello World!' 'Hello World!'
c)
Hello Hello
d)
None of the mentioned
62.
What will be the output of the following Python code?def say(message, times = 1):<br /> print(message * times)<br />say('Hello')<br />say('World', 5)
a)
Hello WorldWorldWorldWorldWorld
b)
Hello World5
c)
Hello World,World,World,World,World
d)
Hello HelloHelloHelloHelloHello
63.
What will be the output of the following Python code? x = 50<br />def func():<br /> global x<br /> print('x is', x)<br /> x = 2<br /> print('Changed global x to', x)<br />func()<br />print('Value of x is', x)
a)
x is 50 Changed global x to 2 Value of x is 50
b)
x is 50 Changed global x to 2 Value of x is 2
c)
x is 50 Changed global x to 50 Value of x is 50
d)
None of the mentioned
64.
What will be the output of the following Python code? def func(a, b=5, c=10):<br /> print('a is', a, 'and b is', b, 'and c is', c) <br />func(3, 7)<br />func(25, c = 24)<br />func(c = 50, a = 100)
a)
      a is 7 and b is 3 and c is 10 a is 25 and b is 5 and c is 24 a is 5 and b is 100 and c is 50
b)
12. a is 3 and b is 7 and c is 10 13. a is 5 and b is 25 and c is 24 14. a is 50 and b is 100 and c is 5
c)
16. a is 3 and b is 7 and c is 10 17. a is 25 and b is 5 and c is 24 18. a is 100 and b is 5 and c is 50
d)
None of the mentioned