wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 30

Worksheet time: 16mins

Name
Class
Date
1.

What is a correct way to declare a Python variable?

a)

var x = 5

b)

#x = 5

c)

$x = 5

d)

x = 5

2.

True or False: You can declare string variables with single or double quotes.

a)

True

b)

False

3.

True or False: Variable names are not case-sensitive.

a)

True

b)

False

4.

Which is NOT a legal variable name?

a)

my-var

b)

my_var

c)

Myvar

d)

_myvar

5.

What is a correct syntax to add the value 'Hello World', to 3 variables in one statement?

a)

x, y, z = 'Hello World'

b)

x = y = z = 'Hello World'

c)

x|y|z = 'Hello World'

6.

Insert the correct syntax to convert x into a floating point number.

a)

float

b)

int

c)

str

7.

Insert the correct syntax to convert x into an integer.

a)

int

b)

float

c)

str

8.

What does the upper() method do?

a)

Returns the string in upper case

b)

Returns the string in lower case

c)

Removes whitespace from the string

d)

Concatenates two strings

9.

What does the lower() method do?

a)

Returns the string in upper case

b)

Returns the string in lower case

c)

Removes whitespace from the string

d)

Concatenates two strings

10.

What does the strip() method do?

a)

Returns the string in upper case

b)

Returns the string in lower case

c)

Removes whitespace from the beginning or end

d)

Concatenates two strings

11.

How do you concatenate two strings in Python?

a)

Using the + operator

b)

Using the - operator

c)

Using the * operator

d)

Using the / operator

12.

What is the correct way to create an f-string?

a)

txt = f'My name is John, I am {age}'

b)

txt = 'My name is John, I am {age}'

c)

txt = 'My name is John, I am ' + age

d)

txt = f'My name is John, I am age'

13.

What does the bool() function do?

a)

Evaluates any value and returns True or False

b)

Converts a string to an integer

c)

Concatenates two strings

d)

Removes whitespace from a string

14.

What is the output of print(10 > 9)?

a)

True

b)

False

c)

None

d)

Error

15.

What does the if statement do?

a)

Tests a condition and executes code based on the result

b)

Defines a function

c)

Creates a loop

d)

Declares a variable

16.

What is the purpose of the else keyword?

a)

Catches anything not caught by preceding conditions

b)

Tests a condition

c)

Defines a function

d)

Creates a loop

17.

What does the and keyword do?

a)

Combines conditional statements and returns True if both are true

b)

Reverses the result of a condition

c)

Tests a single condition

d)

Creates a loop

18.

What does the or keyword do?

a)

Combines conditional statements and returns True if one is true

b)

Reverses the result of a condition

c)

Tests a single condition

d)

Creates a loop

19.

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

a)

def myFunction():

b)

function myFunction()

c)

def myFunction:

d)

myFunction() = def

20.

Which of the following is a valid way to create a dictionary?

a)

myDict = []

b)

myDict = ()

c)

myDict = {}

21.

What is the correct way to create a tuple in Python?

a)

myTuple = ()

b)

myTuple = []

c)

myTuple = {}

22.

True or False:
You can declare string variables with single or double quotes.
x = "John"
# is the same as
x = 'John'

a)

True

b)

False

23.


What will be the result of the following code:
print(float(35))

a)

35

b)

35.0

c)

0.35

24.

The file extension for python is _____________________

a)

.py

b)

.bas

c)

.pptx

d)

.xlsx

25.

Which Python command is used to display information on the screen?

a)

Input

b)

Print

c)

Float

d)

String

26.

Study the code snapshot shown and predict the output.

a)

21

b)

40.0

c)

20.0

d)

none

27.

What is Python?

a)

A snake

b)

A coding language

28.

Which of the following is not a valid comparison operator in Python?

a)

==

b)

!=

c)

<=

d)

><

29.

How do you insert COMMENTS in Python code?

a)

#This is a comment

b)

/* This is a comment */

c)

// This is a comment

30.

Which of these collections defines a LIST?

a)

["apple", "banana", "cherry"]

b)

{"apple", "banana", "cherry"}

c)

("apple", "banana", "cherry")

d)

{"name": "apple", "color": "green"}