Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python

Total questions: 120

Worksheet time: 1hrs 14mins

Name
Class
Date
1.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
2.
What will the output be from the following code?
print("Hello world!")
a)
SyntaxError
b)
Hello world!
c)
"Hello world!"
d)
print(Hello world!)
3.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)
4.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
5.

What will the output be from the following code?

print("Hello world!\nHello world!") (aka new line)

a)

Hello world! Hello world!

b)

Hello world!

Hello world!

c)

SyntaxError

d)

Hello world!

6.
Joining elements together to make a string is called what?
a)
Combining
b)
Connecting
c)
Concatenation
d)
Stringing
7.
Which Python command is used to output information to the screen?
a)
read
b)
output
c)
print
d)
display
8.

What is syntax?

a)

Syntax is the word used to describe an error

b)

Syntax is the rules of the programming language

c)

It is used to read information

d)

It is used to output information

9.
What will the output be from the following code?
print("Hello" + "world!")
a)
Hello world!
b)
Helloworld!
c)
SyntaxError
d)
"Hello" "world!"
10.
What will the output be from the following code?
print("Hello" + "world" + "today")
a)
Helloworldtoday
b)
Hello world today
c)
"Hello" "world" "today"
d)
SyntaxError
11.
To create a newline at the end of prompt, you can use which of the following expressions?
a)
\new
b)
\n
c)
\break
d)
\return
12.
The number or word we give to a variable
a)
Value
b)
Bug
c)
Information
d)
Text
13.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
14.

What symbol is used in python to assign values to a variable? x=coat

a)

equals =

b)

plus +

c)

forward slash /

d)

asterisk *

15.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
16.
What is the name of the programming language we are learning?
a)
Scratch
b)
Python
c)
Pie thin
d)
Scribble
17.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
18.

What will be the output?

name = 'Dave'

greeting = "Good morning" + name

print (greeting)

a)

Good morning 'Dave'

b)

Good morning Dave

c)

Good morning name

d)

Good morning + Dave

19.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
20.
Why is it called 'Python'?
a)
The guy who created it loves snakes
b)
The guy who created it loves Monty Python films
c)
You can create a game on python called snake
d)
It was created by someone called Mr Python
21.
Python is an example of a....
a)
Text-based programming language
b)
Object orientated programming language
c)
language written in java script
d)
Visual-based programming language
22.
What would print (10 + 16) produce?
a)
20
b)
22
c)
24
d)
26
23.
What is python?
a)
a programming language 
b)
DTP software 
c)
Spreadsheet software
d)
Computer 
24.

What would be an example of an integer or whole number?

a)

4

b)

2.5

c)

7.4

d)

9.4

25.
What is the name of the environment in Python that write your programs and then test them out?
a)
Shell
b)
Window
c)
IDLE
d)
CLI
26.
What button do you press to compile (run) your program so that it runs in the shell?
a)
F3
b)
F5
c)
F7
d)
F9
27.

Everything that we want do display in a print() function must:

a)

be inside parentheses - ()

b)

quotation marks - ""

c)

be inside single quotation marks - ''

d)

be inside hash marks - #

28.
Select all the correct answers for float data type:
a)
True
b)
25.4
c)
34
d)
[Hello]
29.

Comments are added in programming to explain what's going on in the code. The computer does not recognize comments. How do you start a comment?

a)

With a ?

b)

With a #

c)

With an !

d)

With a &

30.

In Python, variables are black, functions are purple and strings are green? True or False

a)

True

b)

False

31.

To display something on the screen, use this command:

a)

print()

b)

Print()

c)

screen()

d)

write()

e)

display()

32.

To display the following on screen

Hello World!

the following command should be used:

a)

print(Hello World!)

b)

print("Hello World!")

c)

print("Hello World" + !)

d)

print"(Hello World!)"

33.
Which symbol do we use if we want to add a comment to our code?
a)
@
b)
#
c)
*
d)
&
34.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
35.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
36.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
37.

Which operator performs a division?

a)

-

b)

+

c)

/

d)

*

38.

Which operator checks if a value is equal to another value?

a)

+

b)

=

c)

==

d)

!=

39.

Which operator checks if a value is not equal to another value?

a)

==

b)

+=

c)

!=

d)

=

40.
Converts a number to a string
a)
str()
b)
int()
c)
parseInt()
d)
convert
41.
a data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulo
d)
interpreter
42.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
43.
Which of the following is a float?
a)
new_var = 1234
b)
new_var = True
c)
new_var = 1.234
d)
new_var = "True"
44.
Which of the following is not a string?
a)
new_var = "True"
b)
new_var = "3123"
c)
new_var = "3.123"
d)
new_var = False
45.
Numbers with a decimal point belong to a type called...
a)
pointing
b)
integers
c)
decimal
d)
float
46.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
47.

Which of the following is correct?

a)

Comments are for programmers for better understanding of the program.

b)

Python Interpreter ignores comment.

c)

You can write multi-line comments in Python using triple quotes, either ''' or """.

d)

All of the above

48.

In the following code, n is a/an _______?


n = '5'

a)

integer

b)

string

c)

tuple

d)

operator

49.

What is used to take input from the user in Python?

a)

cin

b)

scanf()

c)

input()

d)

<>

50.

What is a input?

a)

A built-in function that allows us to prompt the user to enter data.

b)

To plug in something.

c)

Data displayed on a screen.

d)

A device.

51.

What syntax would you use to create a name variable?

a)

name=input()

b)

input=name

c)

name=input{}

d)

name=INPUT

52.
What will the output be from the following code?
print("Hello world!\nHello world!")
a)
Hello world! Hello world!
b)
Hello world!
Hello world!
c)

Syntax Error

d)
Hello world!
53.
What will the output be from the following code?
print("Hello" + str(2) + "world!")
a)
Hello world! Hello world!
b)
Hello2world!
c)
Hello Hello world! world!
d)

Syntax Error

54.

What does the following code do? myAge = int(myAge)

a)

Converts the variable myAge to a integer

b)

Syntax Error

c)

Converts the variable myAge from a integer to a string

d)

Missing input

55.
Joining elements together to make a string is called what?
a)
Combining
b)
Connecting
c)
Concatenation
d)
Stringing
56.
Which statement correctly assigns the string "Tanner" to the variable name?
a)
name  = print( "Tanner")
b)
input("Tanner")
c)
name = "Tanner"
d)
name = input("Tanner")
57.

Are Double or single quotes used in Python?

a)

Double

b)

Single

c)

Neither

d)

Both work

58.

Python correct naming convention for variables is?

a)

new_user25

b)

NewUser25

c)

25_new_user

d)

25NewUser

e)

NEWUSER25

59.

The output of the program

x = 4

x = "Sally"

print(x)

a)

four

b)

Saly

c)

Sally

d)

4

60.
What will the output be from the following code?
print("Hello" + 2 + "world")
a)
Hello 2 world
b)
Hello2world
c)
TypeError
d)
HelloHelloworld
61.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
62.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)
63.

What is the name of the variable in this program?

a)

print

b)

colour

c)

input

d)

" "

64.

What will be the output for following python programme:

x = 100

y = float(x)

print(y)

a)

200

b)

100.0

c)

100

d)

Can't convert an integer to a floating number.

65.

Which of the statements below is true about indentation in Python?

a)

Indentation only matters in for loops. Then, everything must be indented one level.

b)

Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.

c)

Indentation always matters in Python. Every statement must be aligned correctly.

d)

Indentation only matters in functions. Then, everything must be indented one level.

66.
Which of the following is a multi-line comment?
a)
"""Multi-line Comment Here"""
b)
""Multi-line Comment Here""
c)
"Multi-line Comment Here"
d)
'Multi-line Comment Here'
67.
Which of the following statements would return the value 2?
a)
new_var = 8 % 3
b)
new_var = 4 % 2
c)
new_var = 10 ** 2
d)
new_var = "4 % 2"
68.
Which of the following text strings is correct?
a)
new_var = "Tim/'s Computer"
b)
new_var = "Tim\'s Computer"
c)
new_var = "Tim's Computer"
d)
new_var = Tim's Computer
69.

Which one is NOT a legal variable name?

a)

_fname

b)

first_Name

c)

f-Name

d)

Fname

70.

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(type of (x))

d)

print(typeOf(x))

71.

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

a)

True

b)

False

c)

Cant say

d)

both are wrong

72.

What is the correct file extension for Python files?

a)

.pyth

b)

.py

c)

.pt

d)

.pyt

73.

Who developed the Python programming language?

a)

Rasmus Lerdorf

b)

Wick van Rossum

c)

Guido van Rossum

d)

Guido Van Stom

74.

Full form of IDLE in python is:

(a)  

75.
What is the meaning of the following comparison operator?
a > b
a)
Greater than
b)
Less than
c)
Not equal to
d)
Greater than or equal to
76.
What is the meaning of the following comparison operator?
a >= b
a)
Equal to
b)
Not equal to
c)
Greater than or equal to
d)
Less than or equal to
77.
The following code is used to create a variable and store a value. Why will it NOT work?
my number = 36
a)
The variable can't store a number
b)
A variable name cannot have any spaces
c)
There variable name can't be called my number
d)
The equals symbol should be at the beginning of the line
78.
What will the output be from the following code?
print("Hello world!" * 2)
a)
TypeError
b)
Hello world world!
c)
Hello world!Hello world!
d)
Hello world! * 2
79.

(a)   is smallest individual unit in a program.

80.

Size of the string "Ant Man"

(a)  

81.

To create a set, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

82.

To create a list, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

83.

To create a tuple, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

84.

To create a dictionary, the following would be used -

a)

( )

b)

[ ]

c)

{ }

d)

{ key : value }

85.

What type of data collection is this?

[ 3, 4, 5, 6 ]

a)

Dictionary

b)

List

c)

Set

d)

Tuple

86.

What type of data collection is this?

( 3, 4, 5, 6 )

a)

Dictionary

b)

List

c)

Set

d)

Tuple

87.

What type of data collection is this?

{ 3, 4, 5, 6 }

a)

Dictionary

b)

List

c)

Set

d)

Tuple

88.

What type of data collection is this?

{ student: "Bill", grade: 92, class: "Python" }

a)

Dictionary

b)

List

c)

Set

d)

Tuple

89.

What is a list in python?

a)

A collection of variables

b)

A collection of items assigned to a single variable

c)

A statement that cant be changed

d)

A Christmas list

90.

Which of these codes is correct for creating a list of numbers?

a)

num = ('10','29','37','109')

b)

num = ['10','29','37','109']

c)

num == ('10','29','37','109')

d)

num = ['10 29 37 109']

91.

What is the index number for 'Spain'?

['England','Brazil','Spain','France']

a)

0

b)

1

c)

2

d)

3

92.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

93.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

94.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

95.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

d)

nameList = [John, Harry, Jesse, John, Harry, Harry]

96.

Which of these pieces of code would return the name "Harry" from the following list?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList()

b)

nameList[1]

c)

NameList(4)

d)

nameList["4"]

97.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

98.

What would this code show on the screen?

a)

7

b)

6

c)

5

d)

4

e)

An error

99.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

100.
What is the output when we execute list(“hello”)?
a)
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b)
 [‘hello’] 
c)
[‘llo’]
d)
 [‘olleh’]
101.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota']

del mariana_islands[0]

print(mariana_islands)

a)

['Saipan', 'Tinian', 'Rota']

b)

['Tinian', 'Rota']

c)

['Saipan', 'Tinian']

d)

['Saipan', 'Rota']

102.

What is the output of program below?


mariana_islands = ['Saipan', 'Tinian', 'Rota']

mariana_islands[0] = 'Guam'

print(mariana_islands)

a)

['Saipan', 'Tinian', 'Rota']

b)

['Guam', 'Tinian', 'Rota']

c)

['Saipan', 'Tinian', 'Rota', 'Guam']

d)

['Guam', 'Saipan', 'Tinian', 'Rota']

103.

nameList = ["John", "Harry", "Jesse", "John", "Marry", "Larry"]

The list will be slice and show Harry and Jesse only. Which piece of code below would do this?

a)

print(nameList[1:3])

b)

print(nameList[0:1])

c)

print(nameList[1:2])

d)

print(nameList["Harry":"Jesse"])

104.

Tuples in Python are mutable

a)

False

b)

True

105.

What is the output of the program above

a)

<class 'tuple'>

b)

<class 'None'>

c)

<class 'list'>

d)

<class 'int'>

106.

What will be the output?

var1=['sam', "Pam", 12,44]

var1[3]="Ram"

print(var1)

a)

['sam', 'Pam', 12, 44]

b)

['sam', 'Pam', 12, 'Ram']

c)

It will give an error

d)

['sam', 'Pam', 'Ram',44]

107.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

108.

Assume the key is the student's id and the value is the grade. Which of the following code will get the grade of student id 102.

a)

grades[102]

b)

grades.get(102)

c)

grades[2]

d)

grades[3]

e)

grades.key(102)

109.

Which of the following statements is used to create an empty set?

a)

{ }

b)

set()

c)

[ ]

d)

( )

110.

If a={5,6,7}, what happens when a.add(5) is executed?

a)

a={5,5,6,7}

b)

a={5,6,7}

c)

Error as there is no add function for set data type

d)

Error as 5 already exists in the set

111.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> a.intersection_update({2,3,4,5})

>>> a

a)

{2,3}

b)

Error, duplicate item present in list

c)

Error, no method called intersection_update for set data type

d)

{1,4,5}

112.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> b=a.copy()

>>> b.add(4)

>>> a

a)

{1,2,3}

b)

Error, invalid syntax for add

c)

{1,2,3,4}

d)

Error, copying of sets isn’t allowed

113.

What will be the output of the following Python code?

s=set()

type(s)

a)

<’set’>

b)

<class ‘set’>

c)

set

d)

class set

114.

Select all of the types of data collections that are ORDERED.

(that means items can be referenced by location or key)

a)

Dictionary

b)

List

c)

Tuple

d)

Set

115.

Select all of the types of data collections that ALLOW duplicate values.

a)

Dictionary

b)

List

c)

Tuple

d)

Set

116.

Select all of the types of data collections that ALLOW individual items within the collection to be changed or modified.

a)

Dictionary

b)

List

c)

Tuple

d)

Set

117.

Which command will allow you to attempt to remove an item from a set without raising an error if it isn't in the set.

a)

.remove( )

b)

.discard( )

c)

.pop( )

d)

.delete( )

118.

Which command will allow you to remove the last item in a collection.

a)

.remove( )

b)

.discard( )

c)

.pop( )

d)

.delete( )

119.

Which command will allow you to attempt to remove an item from a set and will raise an error if it isn't in the set

a)

.remove( )

b)

.discard( )

c)

.pop( )

d)

.delete( )

120.

Which method will combine the contents of two sets WITHOUT changing one of the existing sets?

a)

.update( )

b)

.union( )

c)

.add( )

d)

.intersection( )