wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

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

a)

.python

b)

.py (correct)

c)

.p

d)

.pl

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)

Nothing is printed

c)

Invalid syntax

d)

(7, 6) (correct)

3.

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

a)

// (correct)

b)

%

c)

/

d)

|

4.

Is Python case sensitive when dealing with identifiers?

a)

no

b)

yes (correct)

c)

none of the mentioned

d)

machine dependent

5.

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

a)

Fun

b)

Function

c)

Define

d)

def (correct)

6.

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

a)

anonymous

b)

pi

c)

lambda (correct)

d)

none of the mentioned

7.

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

a)

All of the mentioned (correct)

b)

you can't also create your own functions

c)

Functions are reusable pieces of programs

d)

Functions don't provide better modularity for your application

8.

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

a)

sqrt()

b)

seed()

c)

(soru dosyada eksik/verilmemiş)

9.

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

a)

224

b)

12 (correct)

c)

error

d)

None

10.

All keywords in Python are in

a)

None of the mentioned

b)

lower case (correct)

c)

Capitalized

d)

UPPER CASE

11.

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

a)

random.h

b)

import.random

c)

import random (correct)

d)

random.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)

All of the mentioned. (correct)

d)

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

13.

del method is used to destroy instances of a class.

a)

True

b)

False (correct)

14.

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

a)

none of the mentioned

b)

unlimited length (correct)

c)

all private members must have leading and trailing underscores

d)

underscore and ampersand are the only two special characters allowed

15.

Which type of programming does Python support?

a)

functional programming

b)

structured programming

c)

object-oriented programming

d)

all of the mentioned (correct)

16.

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

a)

str

b)

int

c)

float (correct)

d)

bool

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)

error

b)

0 1 2 (correct)

c)

none of the mentioned

d)

0 1 2 0

18.

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

a)

!

b)

# (correct)

c)

//

d)

/*

19.

What is the correct order of operations in Python?

a)

Parentheses, Exponential, Multiplication, Division, Addition, Subtraction (correct)

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 (correct)

d)

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