wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python 1 Quiz

Total questions: 25

Worksheet time: 50mins

Name
Class
Date
1.

What is a correct syntax to output "Hello World" in Python?

a)

echo "Hello World"

b)

p("Hello World")

c)

print("Hello World")  

d)

output("Hello World");

2.

How do you insert COMMENTS in Python code?

a)

/*This is a comment*/

b)

//This is a comment

c)

#This is a comment  

d)

//This is a comment//

3.

Which one is NOT a legal variable name?

a)

my-var  

b)

_myvar

c)

Myvar

d)

my_var

4.

How do you create a variable with the numeric value 5?

a)

A. x = 5

b)

B. x = int(5)

c)

Both A & B are correct

d)

C. x = five

5.

What is the correct file extension for Python files?

a)

.pyth

b)

.pyt

c)

.py  

d)

.pt

6.

How do you create a variable with the floating number 2.8?

a)

A. x = float(2.8)  

b)

B. x = int(2.8)

c)

C. x = 2.8

d)

Both A & C are correct

7.

What is the correct syntax to output the type of a variable or object in Python?

a)

print(type(x))  

b)

print(typeOf(x))

c)

print(typeof(x))

d)

print(typeof x)

8.

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

a)

def myFunction():  

b)

create myFunction():

c)

function myfunction():

d)

make my_function[ ]:

9.

In Python, 'Hello my friends!', is the same as "Hello my friends!"

a)

True

b)

False

10.

What is a correct syntax to return the first character in a string?

a)

x = sub("Hello", 0, 1)

b)

x = "Hello".sub(0, 1)

c)

x = "Hello"[0]  

11.

Which method can be used to return a string in upper case letters?

a)

toUpperCase()

b)

upperCase()

c)

upper()  

d)

uppercase()

12.

Which method can be used to replace parts of a string?

a)

switch()

b)

replace()  

c)

replaceString()

d)

repl()

13.

Which operator is used to multiply numbers?

a)

%

b)

#

c)

*

d)

x

14.

Which operator can be used to compare two values?

a)

> <

b)

=

c)

< >

d)

==

15.

Which of these collections defines a LIST?

a)

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

b)

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

c)

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

d)

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

16.

Which of these collections defines a TUPLE?

a)

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

b)

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

c)

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

d)

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

17.

How do you start writing an if statement in Python?

a)

if x > y:  

b)

if x > y then:

c)

if (x > y)

d)

what if (x > y):

18.

Which Python list types allow duplicates?

a)

A. List

b)

B. Dictionary

c)

C. Tuple

d)

D. Organized

e)

E. Both A & C are correct

19.

How do you convert to an Integer?

a)

cheese = "3"

cheese = int("3")

print(cheese)

b)

fries = 30

fries = str(30)

print(fries)

c)

pizza = 4

pizza = float(4)

print(pizza)

d)

class = "7"

class = integer(7)

print(class)

20.

True or False: It's okay if your indentation isn't lined up in Python, it won't affect how your code runs.

a)

True

b)

False

21.

What statement will catch everything that is not included in the IF statement?

a)

The CATCH statement

b)

The ELSE statement

c)

The OTHER statement

d)

The THEN statement

22.

What is the output of this code?

rocks = 15

print(rocks / 5)

a)

5

b)

3

c)

Three

d)

rocks, rocks, rocks

23.

In the code "for x in desserts:" what does the x mean?

a)

It's declaring a new variable.

b)

It's adding the letter x to the list.

c)

Literally, the letter x.

d)

It represents each item in the list in turn.

24.

True or False: The code to be executed inside the for loop does not have to be indented.

a)

True

b)

False

25.

In the image, what will the code print out?

a)

I love to play volleyball I love to play basketball I love to play soccer

b)

soccer basketball volleyball

c)

x

d)

I love to play soccer I love to play basketball I love to play volleyball