Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python MCQ Quiz - 45 Sorular

Total questions: 27

Worksheet time: 54mins

Name
Class
Date
1.

Which of the following is the correct extension of the Python file?

a)

.p

b)

.pl

c)

.python

d)

.py

2.

What will be the output of the following Python code? a, b = 6, 7 a, b = b, a a, b

a)

(6, 7)

b)

Invalid syntax

c)

(7, 6)

d)

Nothing is printed

3.

Which of the following is the truncation division operator in Python?

a)

/

b)

//

c)

%

d)

|

4.

Is Python case sensitive when dealing with identifiers?

a)

none of the mentioned

b)

yes

c)

no

d)

machine dependent

5.

Which keyword is used to define a function in Python language?

a)

Define

b)

def

c)

Function

d)

Fun

6.

Python supports the creation of anonymous functions at runtime, using a construct called ________

a)

none of the mentioned

b)

anonymous

c)

pi

d)

lambda

7.

Which one of the following is the use of function in Python?

a)

Functions are reusable pieces of programs

b)

All of the mentioned

c)

you can't also create your own functions

d)

Functions don't provide better modularity for your application

8.

Which of the following functions is a built-in function in Python?

a)

seed()

b)

sqrt()

9.

Consider the code: class tester: def __init__(self, id): self.id = str(id) id = "224" temp = tester(12) print(temp.id)

a)

None

b)

224

c)

error

d)

12

10.

All keywords in Python are in

a)

lower case

b)

UPPER CASE

c)

Capitalized

d)

None of the mentioned

11.

To include the use of functions which are present in the random library, we must use the option:

a)

random.random

b)

random.h

c)

import.random

d)

import random

12.

Which of the following statements about properties is true?

a)

You use properties when you need controlled access or want to encapsulate logic without changing the API.

b)

Properties are useful for validating data, computing attributes, and creating read-only or read-write attributes.

c)

The @property decorator allows you to define getter, setter, and deleter methods for attributes.

d)

All of the mentioned.

13.

del method is used to destroy instances of a class.

a)

True

b)

False

14.

Which of the following is true for variable names in Python?

a)

none of the mentioned

b)

all private members must have leading and trailing underscores

c)

underscore and ampersand are the only two special characters allowed

d)

unlimited length

15.

Which type of programming does Python support?

a)

functional programming

b)

object-oriented programming

c)

all of the mentioned

d)

structured programming

16.

What type does the variable have when the following code line is executed? x = 2 * 3.0

a)

float

b)

bool

c)

str

d)

int

17.

What will be the output of the following Python program? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)

a)

none of the mentioned

b)

error

c)

0 1 2 0

d)

0 1 2

18.

Which of the following character is used to give single-line comments in Python?

a)

//

b)

/*

c)

#

d)

!

19.

What is the correct order of operations in Python?

a)

Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

b)

Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

Parentheses, Exponential, Multiplication, Addition, Division, Subtraction

d)

Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

20.

What will be the output of the following Python code? def foo(): try: return 1 finally: return 2 k = foo() print(k)

a)

1

b)

3

c)

2

d)

error, there is more than one return statement in a single try-finally block

21.

What will be the output of the following Python code? def add(c, k): c.test = c.test + 1 k = k + 1 class A: def __init__(self): self.test = 0 def main(): Count = A() k = 0 for i in range(0, 25): add(Count, k) print("Count.test =", Count.test) print("k =", k) main()

a)

Count.test = 0, k = 0

b)

Exception is thrown

c)

Count.test = 25, k = 25

d)

Count.test = 25, k = 0

22.

Which of the following is a feature of Python DocString?

a)

It provides a convenient way of associating documentation with Python modules, functions, classes, and methods.

b)

All of the mentioned (CORRECT)

c)

Docstrings can be accessed by the doc attribute on objects

d)

In Python all functions should have a docstring

23.

What will be the value of the following Python expression? 9 + 3 % 5

a)

12 (CORRECT)

b)

2

c)

4

d)

1

24.

Which of the following statements are true about opening files?

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 exists, the existing file is overwritten with the new file.

c)

All of the mentioned (CORRECT)

d)

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

25.

Consider: A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Which of the following Python statements will result in the output 6?

a)

A[3][2]

b)

A[1][2]

c)

A[2][1] (CORRECT)

d)

A[2][3]

26.

Which of the following is used to define a block of code in Python language?

a)

Key

b)

Brackets

c)

Indentation

d)

All of the mentioned

27.

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

a)

The id() function compares two objects.

b)

The Python id function returns the unique identity of the object.

c)

Not every object in Python has a unique id.

d)

None of the mentioned