wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Test

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

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

a)

echo("Hello World");

b)

echo "Hello World"

c)

print("Hello World")

d)

p("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

3.

Which one is NOT a legal variable name?

a)

_myvar

b)

my_var

c)

Myvar

d)

my-var

4.

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

a)

x = int(5)

b)

x = 5

c)

Both answers are correct

5.

What is the correct file extension for Python files?

a)

.pt

b)

.pyth

c)

.pyt

d)

.py

6.

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

a)

x = float(2.8)

b)

Both answers are correct

c)

x = 2.8

7.

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

a)

print(typeOf(x))

b)

print(typeof x)

c)

print(typeof(x))

d)

print(type(x))

8.

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

a)

create myFunction():

b)

function myfunction():

c)

def myFunction():

9.

In Python, 'Hello', is the same as "Hello"

a)

True

b)

False

10.

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

a)

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

b)

x = "Hello"[0]

c)

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

11.

Which method can be used to remove any whitespace from both the beginning and the end of a string?

a)
strip()
b)
trim()
c)

len()

d)

ptrim()

12.

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

a)

upperCase()

b)

uppercase()

c)

toUpperCase()

d)

upper()

13.

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

a)

replace()

b)

repl()

c)

replaceString()

d)

switch()

14.

Which operator is used to multiply numbers?

a)

*

b)

x

c)

#

d)

%

15.

Which operator can be used to compare two values?

a)

==

b)

=

c)

<>

d)

><

16.

Which of these collections defines a LIST?

a)

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

b)

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

c)

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

d)

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

17.

Which of these collections defines a TUPLE?

a)

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

b)

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

c)

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

d)

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

18.

Which of these collections defines a SET?

a)

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

b)

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

c)

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

d)

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

19.

Which of these collections defines a DICTIONARY?

a)

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

b)

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

c)

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

d)

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

20.

Which collection is ordered, changeable, and allows duplicate members?

a)

LIST

b)

DICTIONARY

c)

SET

d)

TUPLE

21.

Which collection does not allow duplicate members?

a)

TUPLE

b)

LIST

c)

SET

22.

How do you start writing an if statement in Python?

a)

if x > y then:

b)

if (x > y)

c)

if x > y:

23.

How do you start writing a while loop in Python?

a)

while x > y:

b)

while x > y {

c)

x > y while {

d)

while (x > y)

24.

How do you start writing a for loop in Python?

a)

for x in y:

b)

for each x in y:

c)

for x > y:

25.

Which statement is used to stop a loop?

a)

break

b)

exit

c)

stop

d)

return