wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following is a valid Python variable name?

a)

2variable

b)

_variable

c)

variable-name

d)

for

2.

What will be the output of the following code?

x = 5

X = 10

print(x, X)

a)

5 10

b)

10 5

c)

Error

d)

55

3.

Which of the following is NOT a valid identifier in Python?

a)

my_var

b)

class

c)

myVar123

d)

var_2x

4.

What is the correct way to define a variable in Python?

a)

int x = 10;

b)

x := 10

c)

x = 10

d)

10 = x

5.

Which of the following is a Python keyword?

a)

print

b)

input

c)

break

d)

none

6.

What is the correct syntax to print "Hello, Python!" in Python 3?

a)

print "Hello, Python!"

b)

print(Hello, Python!)

c)

print("Hello, Python!")

d)

echo "Hello, Python!"

7.

What will be the output of the following code?

print("Python", "is", "fun", sep="-")

a)

Python-is-fun

b)

Python is fun

c)

Python-is-fun-

d)

Pythonisfun

8.

What does the end parameter in the print() function do?

a)

Specifies the ending character of the output

b)

Stops the execution

c)

Adds a new line after the output

d)

Terminates the program

9.

What is the default separator in Python's print() function?

a)

, (comma)

b)

" " (space)

c)

\n (new line)

d)

. (dot)

10.

What is the output of this code?

x = "10"

y = "20"

print(x + y)

a)

30

b)

1020

c)

Error

d)

10 20

11.

What error will the following code produce?

x = 5

y = "Hello"

print(x + y)

a)

SyntaxError

b)

TypeError

c)

ValueError

d)

No error

12.

What error will occur in this program?

for i in range(5)

print(i)

a)

SyntaxError

b)

IndentationError

c)

NameError

d)

TypeError

13.

What error will occur here?

def myFunction()

print("Hello")

a)

SyntaxError

b)

IndentationError

c)

RuntimeError

d)

TypeError

14.

What will the following code print?

print("5" * 3)

a)

555

b)

15

c)

Error

d)

5 5 5

15.

What is the error in this program?

print "Hello, World!"

a)

SyntaxError

b)

IndentationError

c)

Logical Error

d)

No Error

16.

Which function is used to take user input in Python?

a)

scan()

b)

input()

c)

read()

d)

cin>>

17.

What is the output of this code?

x = input("Enter a number: ")

print(type(x))

a)

<class 'int'>

b)

<class 'str'>

c)

<class 'float'>

d)

<class 'input'>

18.

What is the output of this code?

print(3 * "Hello ")

a)

Hello Hello Hello

b)

HelloHelloHello

c)

3Hello

d)

Error

19.

What does int("10") + int("20") return?

a)
30
b)

20

c)

10

d)

None

20.

What does len("Python") return?

a)
6
b)

5

c)

4

d)

3

21.

Which operator is used for exponentiation in Python?

a)

^

b)

**

c)

&

d)

*

22.

How many keywords are there in Python 3.10?

a)

33

b)

35

c)

36

d)

38

23.

Which of the following is NOT a Python keyword?

a)

yield

b)

global

c)

define

d)

nonlocal

24.

Which keyword is used to define a function in Python?

a)

function

b)

define

c)

def

d)

fun

25.

Which of the following is a looping keyword in Python?

a)

loop

b)

repeat

c)

for

d)

do