wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics Test

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which is the correct way to create a variable in Python?

a)

x = 5

b)

5 = x

c)

int x = 5

d)

var x = 5

2.

Which variable name is valid?

a)

2name

b)

pizza_size

c)

your-age

d)

print

3.

What will this code print? x = 10 print(x)

a)

10

b)

x

c)

"x"

d)

Error

4.

What does input("Enter your name: ") do?

a)

Prints the name

b)

Asks the user to type something

c)

Creates a variable

d)

Runs the program

5.

By default, the result of input() is:

a)

int

b)

str

c)

float

d)

bool

6.

Which of these is correct syntax to print a message?

a)

print "Hello"

b)

print(Hello)

c)

print("Hello")

d)

echo("Hello")

7.

Which arithmetic operator is used for multiplication?

a)

x

b)

*

c)

×

d)

mul

8.

What is 15 + 7?

a)

21

b)

22

c)

23

d)

20

9.

What is the result of 20 - 8?

a)

14

b)

10

c)

12

d)

18

10.

What is the result of 5 * 6?

a)

25

b)

35

c)

30

d)

60

11.

What is the result of 12 / 3?

a)

4

b)

6

c)

3

d)

9

12.

Which code correctly converts "25" into an integer?

a)

int("25")

b)

str("25")

c)

25("int")

d)

float(25)

13.

What is the result of float("3")?

a)

"3.0"

b)

3.0

c)

3

d)

Error

14.

Which code changes number 50 into a string?

a)

str(50)

b)

int("50")

c)

float("50")

d)

"50" + 50

15.

What will this code print? name = "Nada" print("Hello " + name)

a)

Hello Nada

b)

name

c)

"Hello Nada"

d)

Hello + name

16.

Which of these is a string in Python?

a)

"apple"

b)

42

c)

3.14

d)

True

17.

Which of these is correct?

a)

print("5 + 3") → prints 8

b)

print(5 + 3) → prints 8

c)

print("5" + 3) → prints "53"

d)

print(5 " + " 3)

18.

Which of these lines will give an error?

a)

x = "10"

b)

y = int(x)

c)

z = x + y

d)

print(z)

19.

Which is the correct way to write a string in Python?

a)

text = 'Hello'

b)

text = "Hello"

c)

Both a and b

d)

None

20.

Which function is always written with parentheses in Python?

a)

input

b)

print

c)

int

d)

All of the above