wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 45

Worksheet time: 23mins

Name
Class
Date
1.

Who developed Python?

a)

Dennis Ritchie

b)

Guido van Rossum

c)

James Gosling

d)

Bjarne Stroustrup

2.

Which of the following is true about Python?

a)

Python is an interpreted language

b)

Python is a compiled language

c)

Python is a low-level language

d)

Python is a hardware-dependent language

3.

What will be the output of the following code? print("Hello\nWorld")

a)

Hello World

b)

Hello

World

c)

Hello\nWorld

d)

Error

4.

What will be the output of the following code if the user enters 5? x = input("Enter a number: ") print(type(x))

a)

<class 'int'>

b)

<class 'str'>

c)

<class 'float'>

d)

Error

5.

What will be the output of the following code?

x = 10

y = x

x = 20

print(y)

a)

10

b)

20

c)

Error

d)

None

6.

Which statement is used to display output in Python?

a)

display()

b)

echo()

c)

print()

d)

output()

7.

Which extension is used for Python files?

a)

.py

b)

.java

c)

.c

d)

.exe

8.

What is the output of the following code?

a, b = 5, 10

a, b = b, a

print(a, b)

a)

5 10

b)

10 5

c)

Error

d)

None

9.

What is the main difference between a program and a script in Python?

a)

A program is compiled, while a script is interpreted

b)

A program cannot be executed, while a script can

c)

A script is written in Java, while a program is written in Python

d)

There is no difference

10.

Which of the following is typically true about scripts?

a)

They are large and complex

b)

They are executed line by line

c)

They require a separate compiler

d)

They must be written in C++

11.

What is the output of the following code?

x = 5

y = x ** 2

print(y)

a)

10

b)

25

c)

5

d)

Error

12.

Python uses which of the following?

a)

Compiler

b)

Interpreter

c)

Both

d)

None

13.

What will be the output of the following code?

s = "Python"

print(s[::-1])

a)

nohtyP

b)

Python

c)

Pyt

d)

Error

14.

What does an interpreter do?

a)

Converts the entire code at once

b)

Translates code line by line

c)

Checks syntax errors after execution

d)

Creates an executable file

15.

Which of the following is NOT a token in Python?

a)

Keywords

b)

Variables

c)

Functions

d)

Operators

16.

Which of the following is NOT a valid Python variable name?

a)

my_var

b)

2var

c)

_name

d)

var_name

17.

How do you write a comment in Python?

a)

// Comment

b)

/* Comment */

c)

# Comment

d)

-- Comment

18.

Which of the following is not a Python keyword?

a)

True

b)

False

c)

None

d)

value

19.

What is the output of type(10.5)?

a)

int

b)

float

c)

double

d)

decimal

20.

Which of the following is a mutable data type in Python?

a)

Tuple

b)

String

c)

List

d)

Set

21.

What will be the result of 3 + 5 * 2?

a)

16

b)

13

c)

10

d)

11

22.

What function is used to take user input in Python?

a)

scan()

b)

input()

c)

read()

d)

enter()

23.

What will be the output of print("Hello", "World", sep="-")?

a)

Hello-World

b)

Hello World

c)

Hello, World

d)

HelloWorld

24.

What will "hello"[1:4] return?

a)

h

b)

ell

c)

llo

d)

hello

25.

What will be the output of the following code?

name = "Alice"

age = 25

print(f"My name is {name} and I am {age} years old.")

a)

My name is Alice and I am 25 years old.

b)

My name is {name} and I am {age} years old.

c)

Error

d)

None

26.

What will be the result of "Python".upper()?

a)

python

b)

PYTHON

c)

PytHoN

d)

None

27.

Which of the following is a correct syntax for an if statement in Python?

a)

if x > 5 then:

b)

if (x > 5):

c)

if x > 5:

d)

if x > 5 {}

28.

What will be the output of the following code?

x = 10

if x % 2 == 0:

print("Even")

else:

print("Odd")

a)

Even

b)

Odd

c)

Error

d)

None

29.

Which loop executes at least once, regardless of the condition?

a)

for loop

b)

while loop

c)

do-while loop

d)

None of the above

30.

What will be the output of the following code?

for i in range(1, 5):

print(i, end=" ")

a)

1 2 3 4

b)

1 2 3 4 5

c)

0 1 2 3 4

d)

Error

31.

How many times will the loop execute?

i = 1

while i < 5:

print(i, end=" ")

i += 1

a)

1 time

b)

4 times

c)

Infinite

d)

Error

32.

What keyword is used to define a function in Python?

a)

define

b)

function

c)

def

d)

fun

33.

What will be the output of the following function?

def test(a, b=5):

return a * b

print(test(3))

a)

3

b)

15

c)

5

d)

Error

34.

What will be the output of the following function?

def greet(name="Guest"):

print("Hello", name)

greet()

a)

Hello Guest

b)

Hello

c)

Error

d)

None

35.

What does a return statement do in Python?

a)

Stops the function execution and returns a value

b)

Stops the program execution

c)

Skips a statement

d)

None of the above

36.

What is recursion in Python?

a)

A function calling itself

b)

A function calling another function

c)

A function that repeats

d)

None of the above

37.

What is the output of the following recursive function?

def fact(n):

if n == 0:

return 1

return n * fact(n - 1)

print(fact(3))

a)

3

b)

6

c)

9

d)

Error

38.

Which of the following is a valid lambda function?

a)

lambda x, y: x + y

b)

lambda (x, y) -> x + y

c)

lambda x y: x + y

d)

def lambda(x, y): return x + y

39.

What is the output of the following lambda function?

square = lambda x: x * x

print(square(4))

a)

8

b)

16

c)

Error

d)

None

40.

What is the correct way to swap two variables in Python?

a)

temp = a; a = b; b = temp

b)

a, b = b, a

c)

swap(a, b)

d)

None of the above

41.

What will be the output of the following code?

lst = [10, 20, 30, 40, 50]

print(lst[1:4])

a)

[10, 20, 30]

b)

[20, 30, 40]

c)

[30, 40, 50]

d)

Error

42.

What is the output of the following list comprehension?

lst = [x for x in range(5)]

print(lst)

a)

[0, 1, 2, 3, 4]

b)

[1, 2, 3, 4, 5]

c)

Error

d)

None

43.

How do you calculate the Euclidean distance between two points (x1, y1) and (x2, y2)?

a)

((x2 - x1) + (y2 - y1))

b)

((x2 - x1)**2 + (y2 - y1)**2) ** 0.5

c)

(x1 - x2) + (y1 - y2)

d)

(x1 * x2) + (y1 * y2)

44.

What is the output of the following code?

def add_sub(x,y):

  c=x+y

  d=x-y

  return c,d

print(add_sub(10,5))

a)

(15,10)

b)

(15,15)

c)

(15,5)

d)

(5,15)

45.

What is the output of the following code?

def func(a, b=5, c=10):

  print ('a is', a, 'and b is', b, 'and c is', c)

func(3, 7)

a)

a is 3 and b is 7 and c is 10

b)

a is 3 and b is 5 and c is 10

c)

a is 3 and b is 7 and c is 7

d)

a is 3 and b is 3 and c is 10