wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python 101 Quiz - 101 Questions

Total questions: 101

Worksheet time: 51mins

Name
Class
Date
1.

What will this code result to?

print(len("🤚"))

a)

Syntax error

b)

1

c)

2

d)

3

2.

Solve this python code and choose the correct answer.

print(len("👩‍👩‍👦‍👦")

a)

Syntax error

b)

1

c)

4

d)

7

3.

How can you insert comments in python?

a)

/*This is a comment*/

b)

'''This is a comment'''

c)

#This is a comment

d)

//This is a comment

4.

Which of these is an incorrect python syntax for variables?

a)

myvar

b)

_myvar

c)

MyVar

d)

my-var

5.

How do you create a variable with numeric value 5987658765 in python?

a)

a = 5987658765

b)

x = int(5987658765)

c)

Is is not possible to create a variable of such a large value in python

d)

none of these

6.

Python files should always have the following extension

a)

.python

b)

.txt

c)

.py

d)

.pytn

7.

How do you create a floating-point variable with value 5.9?

a)

x = 5.9

b)

y = float(5.9)

c)

a = 5 + 0.9

d)

b = 6 - 0.1

8.

Choose the correct syntax for showing the type of variable or object?

a)

print(typeof(a))

b)

print(type(a))

c)

print(typeOf(a))

d)

print(typeof_a)

9.

Choose the right syntax for creating a function

a)

def my_function():

b)

create myfunction():

c)

name myfunction():

d)

none of these

10.

In python, which of these will print Hey There

a)

"Hey There"

b)

'Hey There'

c)

'''Hey There'''

d)

None of the above

11.

Write the correct syntax for getting the first letter of the string

a)

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

b)

x = sub("hello", 0)

c)

x = "Hello"[0]

d)

x = snip("Hello",0)

12.

Which of these inbuilt python function helps remove whitespace at both ends of a string?

a)

remove()

b)

trip()

c)

strip()

d)

rem()

13.

Which method will help you change all the string values to upper case?

a)

UpperCase()

b)

UC()

c)

upper()

d)

upperCase()

14.

------- method helps you replace the parts of a string

a)

replace()

b)

repl()

c)

switch()

d)

replaceString()

15.

Which of these operators helps you get the floor division in python?

a)

_

b)

/

c)

//

d)

%

16.

If a = 50//3, then print(a) would output?

a)

125000

b)

16.666666

c)

16

d)

17

17.

If a = 50 % 25, what would print(a) result to?

a)

0

b)

1

c)

2

d)

1.0

18.

Which operator helps you compare two values?

a)

<>

b)

=

c)

==

d)

><

19.

Which of these is a LIST in python?

a)

("apple", "banana", "orange")

b)

["apple", "banana", "orange"]

c)

{"apple", "banana", "orange"}

d)

{1:"apple", 2:"banana", 3:"orange"}

20.

Which of these is a TUPLE in python?

a)

("apple", "banana", "orange")

b)

["apple", "banana", "orange"]

c)

{"apple", "banana", "orange"}

d)

{1:"apple", 2:"banana", 3:"orange"}

21.

Which of these is a DICTIONARY in python?

a)

("apple", "banana", "orange")

b)

["apple", "banana", "orange"]

c)

{"apple", "banana", "orange"}

d)

{1:"apple", 2:"banana", 3:"orange"}

22.

Which of these is a SET in python?

a)

("apple", "banana", "orange")

b)

["apple", "banana", "orange"]

c)

{"apple", "banana", "orange"}

d)

{1:"apple", 2:"banana", 3:"orange"}

23.

Which of these collections in python is ordered, changeable and also allows duplicate values?

a)

tuple

b)

list

c)

dictionary

d)

set

24.

Which of these python collections does not allow duplicate values?

a)

tuple

b)

list

c)

set

d)

dictionary

25.

What is the correct syntax for writing an if condition in python?

a)

if x > y

b)

if x > y:

c)

if x > y then:

d)

if x is greater than y:

26.

Choose the correct syntax for writing a for loop in python

a)

for every x in y:

b)

for each x in y:

c)

for x in y:

d)

for all x in y:

27.

Which of the following statements is used to exit a loop in python?

a)

stop

b)

exit

c)

return

d)

break

28.

Add the missing part of the code to output

____("Hello World")

a)

print

b)

output

c)

run

d)

type

29.

___is a comment.

Fill in the blank to make it a comment.

a)

??

b)

//

c)

@

d)

#

30.

Fill in the blanks to make a variable named carname with the value Volvo

---- = '----'

a)

'carname', Volvo

b)

carname, "Volvo"

c)

carname, Volvo

d)

"carname", "Volvo"

31.

Fill in the blanks to make a variable named x with the value 100

---- = ----

a)

x, 100

b)

x, "100"

c)

"x", "100"

d)

none

32.

Display the sum of 5+10 using two variables a and b. Choose the values to fill in the blanks

a)

a, 5, -

b)

b, 10, +

c)

a, 5, +

d)

b, 10, -

33.

Remove the unnecesary character/s in the variable name

2my-firstname = 'Python'

a)

2,m

b)

2,m,y

c)

2,-

d)

-

34.

Add the correct syntax to the blank spaces to assign same value to all the variables

a___b___c= 'Python'

a)

,

b)

+

c)

=

d)

.

35.

What would be the anwer to the following code?

x = 10

print(type(x))

a)

str

b)

float

c)

int

d)

lst

36.

What would be the anwer to the following code?

x = "Hey There"

print(type(x))

a)

str

b)

float

c)

int

d)

lst

37.

What would be the anwer to the following code?

x = 9.8

print(type(x))

a)

str

b)

float

c)

int

d)

flt

38.

What would be the anwer to the following code?

x = ("apple", "banana", "cherry")

print(type(x))

a)

tuple

b)

str

c)

list

d)

set

39.

What would be the anwer to the following code?

x = {"name" : "John", "age" : 36}

print(type(x))

a)

tuple

b)

dict

c)

list

d)

set

40.

What would be the anwer to the following code?

x = True

print(type(x))

a)

True

b)

boolean

c)

False

d)

bool

41.

Add the correct syntax to change it into a floating point number

a = 500

a = ____(a)

a)

flt

b)

floater

c)

float

d)

int

42.

Add the correct syntax to change it into an integer

a = 500.00

a = ____(a)

a)

flt

b)

floater

c)

float

d)

int

43.

Add the correct syntax to change it into a complex number

a = 500.00

a = ____(a)

a)

cmp

b)

complex

c)

comp

d)

c

44.

Which method allows you to find the length of a string?

a)

length

b)

len

c)

string

d)

trim

45.

Choose the syntax to slice the first character of the string.

txt = "Hey There"

slice=_____

a)

slice.txt

b)

trim.txt

c)

txt[0]

d)

snip(txt)

46.

Choose the syntax to slice the characters from index position 2 to 4 of the string.

txt = "Hey There"

slice=_____

a)

txt[2]

b)

txt[2:4]

c)

txt[2:5]

d)

txt[:5]

47.

Fill the code in the blank area to remove any whitespace from the start and end of the string.

txt = " Hello World "

x =

a)

trim.txt

b)

strip.txt

c)

txt.strip()

d)

txt.trim()

48.

Change the value in txt to lower case

x = "Hey There"

x = ______

a)

LowerCase(txt)

b)

txt.lower()

c)

txt.lowercase()

d)

lower(txt)

49.

Change the value in txt to upper case

x = "Hey There"

x = ______

a)

UpperCase(txt)

b)

txt.upper()

c)

txt.uppercase()

d)

upper(txt)

50.

Replace the character I with Y

txt = "Patrick loves fish"

txt = _____

a)

txt.rep("I", "Y")

b)

txt.replace("I","Y")

c)

replace.txt(I,Y)

d)

rep.txt(I,Y)

51.

Insert the correc syntax to add a placeholder for the age parameter

age = 36

txt = "My name is John, and I am ____ "

print(txt.format(age))

a)

[]

b)

{}

c)

()

d)

<>

52.

What would the following statement print

print(10>9)

a)

10>9

b)

10 is greater than 9

c)

True

d)

False

53.

What would the following statement print

print(10==9 and len("hey"==3))

a)

True

b)

Not True

c)

Not False

d)

False

54.

What would the following statement print

print(10!=9 or len("hey"==5))

a)

True

b)

Not True

c)

Not False

d)

False

55.

What would the following statement print

print(bool("abcdef"))

a)

True

b)

Not True

c)

Not False

d)

False

56.

What would the following statement print

print(bool(0))

a)

True

b)

Not True

c)

Not False

d)

False

57.

fruits = ["apples", "bananas", "oranges"]

if "apples" ___ fruits:

Choose the correct operator to fill in the blank

a)

is there

b)

in there

c)

part of

d)

in

58.

Change the value of the first fruit in the fruit list to kiwi

fruits = ["apple", "banana", "cherry"]

___ = ___

a)

fruits=fruits[1]

b)

fruits[0]="kiwi"

c)

fruits[1]="kiwi"

d)

kiwi=fruits[0]

59.

Specify which is the correct code to add orange to the fruit list

fruits = ["apple", "banana", "cherry"]

________

a)

fruits.append(orange)

b)

fruit.add(orange)

c)

fruits.append('orange')

d)

fruit.add('orange')

60.

Specify which is the correct code to insert orange to the fruit list as the second item

a)

fruits.insert(1,"orange")

b)

fruits.insert(1,orange)

c)

fruits.append('orange')

d)

fruit.add('orange')

61.

Specify which is the correct code to remove cherry to the fruit list as the second item

fruits = ["apple", "banana", "cherry"]

a)

fruits.remove("cherry")

b)

fruits.remove(cherry)

c)

fruits.del(cherry)

d)

fruit.add('orange')

62.

Print the last item on this list using negative index

fruits = ["apple", "banana", "cherry"]

a)

print(fruits[1])

b)

print(fruits[-1])

c)

print(fruits[0])

d)

print(fruits[-2])

63.

fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]

Choose the correct syntax to print all the fruits from banana to kiwi

a)

print(fruits)

b)

print(fruits[0,2,4]

c)

print(fruits[1:5])

64.

fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]

Choose the correct syntax to print number of items in this list

a)

print(fruits)

b)

print(len(fruits)

c)

print(len(fruits))

d)

none

65.

Choose the correct option to print the first item in this tuple

fruits = ("apple", "banana", "cherry")

a)

print(fruits(1))

b)

print(fruits(0))

c)

print(fruits[1])

d)

print(fruits(01))

66.

Choose the correct option to print the number of items in this tuple

fruits = ("apple", "banana", "cherry")

a)

print(len[fruits])

b)

print(fruits(len))

c)

print(length(fruits))

d)

print(len(fruits))

67.

Print the last value in the tuple below using negative indexing

fruits = ("apple", "banana", "cherry")

a)

print(fruits[2])

b)

print(fruits[0])

c)

print(fruits[1])

d)

print(fruits[-1])

68.

For the set below, how can you add another item orange to it.

fruits = {"apple", "banana", "cherry"}

a)

fruits.add{"orange"}

b)

fruits.add("orange")

c)

fruits.add["orange"]

d)

none

69.

Use the correct method to add more than one items(more_fruits) to the set

fruits = {"apple", "banana", "cherry"}

more_fruits = ["orange", "mango", "grapes"]

a)

fruits.add(more_fruits)

b)

fruits.update(more_fruits)

c)

fruits.increase(more_fruits)

d)

fruits.append(more_fruits)

70.

Use the correct method to remove banana from the set

fruits = {"apple", "banana", "cherry"}

a)

fruits.remove("banana")

b)

fruits.discard("banana")

c)

fruits.increase(more_fruits)

d)

fruits.append(more_fruits)

71.

For the dictionary, print the model of the car using the get method

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

a)

print(get("model")

b)

print(get.car("model")

c)

print(car.get("model")

d)

none

72.

For the dictionary, change the value of year to 2022

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

a)

year=2022

b)

car(year)=2022

c)

car["year"]=2022

d)

car.year=2022

73.

Add the key/value pair "color" : "red" to the car dictionary.

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

a)

car['color']:'red'

b)

car['color']='red'

c)

car('color')='red'

d)

car["color"]="red"

74.

Use the pop method to remove the model from the dictionary

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

a)

car.pop('model')

b)

car.rem('model')

c)

car.pop("model")

d)

car.pop['model']

75.

Which method will help you clear this dictionary

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

a)

car.clear()

b)

car.rem()

c)

car.pop()

d)

car.remove()

76.

Print "Hello World" if a is greater than b.

a = 50

b = 10

___a___b___

print("Hello World")

Fill in the empty values

a)

if, <=, :

b)

if, <, :

c)

if, >=, ;

d)

if, >, :

77.

Print "Hello World" if a is equal to b, else print "No"

Fill in the empty values

a)

if, ==, :, else

b)

if, >=, :, else

c)

if, >=, ;, else

d)

if, >, :, else

78.

What does this code do

a)

prints all the numbers from 1 to 6 in a column

b)

prints all the numbers from 1 to 5 in a column

c)

prints all the numbers from 1 to 5 in a row

d)

prints all the numbers from 1 to 6 in a row

79.

What does this code result in?

a)

prints all the values from 1 to 6

b)

prints all the values from 1 to 3

c)

breaks the code

d)

prints all the values from 1 to 4

80.

What would happen when you run this code?

a)

print the numbers 1,2,3,4,5

b)

print numbers 1,2,3,4,5,6

c)

print numbers from 1,2,4,5,6

d)

print numbers 1,3,4,5

81.
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
82.
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
83.
What Python command lets the user enter an answer to a question?
a)
answer()
b)
open()
c)
print()
d)
input()
84.

Python correct naming convention for variables is?

a)

new_user25

b)

NewUser25

c)

25_new_user

d)

25NewUser

e)

NEWUSER25

85.

If you want to create an empty list called colours in Python, which of the following is correct?

a)

colours = [ ]

b)

colours = ( )

c)

colours = { }

d)

colours = <>

86.
What output will this code produce?
a)
4
b)
2
c)
3
d)
5
87.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17
88.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
89.

print("12"*3) What would this print?

a)
36
b)
121212
c)
24
d)
12*3
90.

print("12"*3) What would this print?

a)
36
b)
121212
c)
24
d)
12*3
91.

What will the output be from the following Python code?

print(9/3)

a)

3

b)

3.0

c)

9/3

d)

SyntaxError

92.
runs code line by line and checks for errors
a)
interpreter
b)
variable
c)
modulo
d)
boolean
93.

Which commands might be correct?

a)

random. random(1, 10)

b)

print(random.random( ))

c)

print(random. randint(1,10))

d)

import.random(2.7)

94.

How do you define(assign) variables?

a)

var="String"

b)

func==Hello

c)

var : 123

d)

word= Hello

95.

Which one does take you to next line?

a)

\t

b)

\n

c)

/n

d)

\\

96.

Which of the following sequences would be generated by the given line of code?

range (10, 0, -5)

a)

10,9,8,7,6,5

b)

10, 5

c)

0, 5, 10

d)

10, 5, 0

97.

In a Python program, what would be the increment value for the looping variable in the FOR LOOP code?

for x in range (25, 10, -5)

a)

10

b)

-5

c)

25

d)

5

98.

Which of the following is a data type in Python?

a)

int

b)

words

c)

string

d)

decimals

99.

x = 23

y = 3

print(x // y)

a)

7

b)

7.6666

c)

7.7

d)

Error

100.

What is the output of the code shown in the image?

a)

2

b)

3

c)

'2'

d)

'3'

101.

What is the output of the code shown in the image?

a)

#

#

#

#

b)

####

c)

#

##

###

####

d)

#

##

###

####

#####