Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python basics

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which function is used to display output on the console in Python?

a)

input()

b)

print()

c)

display()

d)

output()

2.

How do you get user input in Python?

a)

get()

b)

input()

c)

user_input()

d)

read()

3.

Which operator is used to assign a value to a variable in Python?

a)

==

b)

<=

c)

=

d)

-=

4.

What is the result of the following expression: 5 + 3 * 2?

a)

10

b)

11

c)

16

d)

13

5.

Which operator is used for exponentiation in Python?

a)

^

b)

//

c)

%

d)

**

6.

Which logical operator is used to perform a logical AND operation in Python?

a)

&

b)

&&

c)

|

d)

and

7.

What will be the output of the following expression: 10 > 5 and 3 < 2?

a)

True

b)

False

c)

Error

d)

None

8.

How do you convert a variable to an integer in Python?

a)

to_int()

b)

cast_int()

c)

int()

d)

convert_int()

9.

Which conditional statement is used to execute a block of code when a condition is true?

a)

for

b)

while

c)

if

d)

else

10.

What is the syntax for a for loop in Python?

a)

for i in range(start, end):

b)

for i in range(end):

c)

for i in range(start, end, step):

d)

for i in range(end, start, -step):

11.

How do you exit a loop prematurely in Python?

a)

exit()

b)

break()

c)

continue()

d)

stop()

12.

What is the output of the following code snippet

x = 10

while x > 0:

print(x)

x -= 1

a)

10, 9, 8, 7, 6, 5, 4, 3, 2, 1

b)

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

c)

10

d)

None

13.

Which of the following is NOT a valid casting function in Python?

a)

int()

b)

cast()

c)

float()

d)

str()

14.

What will be the output of the following code snippet?

x = 5

if x > 2 and x < 10:

print("Valid")

else:

print("Invalid")

a)

valid

b)

error

c)

invalid

d)

None

15.

Which operator is used to concatenate two strings in Python?

a)

*

b)

-

c)

&

d)

+