Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python

Total questions: 30

Worksheet time: 18mins

Name
Class
Date
1.

How do you access the first item in a list named shopping?

a)

shopping[1]

b)

shopping[0]

c)

shopping[first]

d)

shopping[-1]

2.

Which statement prints 7 (Select 2 answers)

a)

print 7

b)

print("7"

c)

print("7")

d)

print(3 + 4)

3.

Which of the following functions is used to count the number of elements in a list ?

a)

count( )

b)

find( )

c)

len( )

d)

index( )

4.

The correct syntax for converting the string x to uppercase is :

a)

upper.x()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

5.

Unchangeable data stored in parentheses ( )

a)

Containers

b)

List

c)

Tuple

d)

Variable

e)

Syntax

6.

All whole numbers (both positive and negative) and zero. These numbers cannot have decimal places.

a)

Integer

b)

Float

c)

Value

d)

Error

e)

Fraction

7.

List items have an index number. In the following list, which item has the index number of 3?

["Barry", "Harry", "Jesse", "John", "Peter", "Harry"]

a)

"Barry"

b)

"Harry"

c)

"Jesse"

d)

"John"

8.

If L1=[2, 4, 8, 16] and L2=[32, 64]

what will result from L1+L2?

a)

[2,4,8,16,32,64]

b)

[2,4,8,16][32,64]

c)

[2,4,8,16],[32,64]

d)

2468163264

9.

What is the index number/ position for 'Spain'?

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

a)

0

b)

1

c)

2

d)

3

10.

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']

11.

Let x= "Python", the output of print(x.upper()) is

a)

python

b)

PYTHON

c)

_PYTHON

d)

"PYTHON"

12.

If list1=[17,23,41,10]

then list1.append(32) will result in:

a)

[32,17,23,41,10]

b)

[17,23,41,10,32]

c)

[10,17,23,32,41]

d)

[41,32,23,17,10]

13.

Suppose you have the following tuple definition:


t = ('foo', 'bar', 'baz')


Which of the following statements replaces the second element ('bar') with the string 'qux':

a)

t[1] = 'qux'

b)

t(1) = 'qux'

c)

t[1:1] = 'qux'

d)

It’s a trick question—tuples can’t be modified.

14.

If L1=[2,4,8,16] what is the result of print(16 in L1)

a)

True

b)

False

15.

Let x= "Python", the output of

print(x[0])

print(x[1])

print(x[2])

a)

PYT

b)

P

y

t

c)

T

h

o

d)

n

oh

16.

In Python, this is the command that tells the program what to show on the screen

a)

Expression

b)

Script

c)

Print

d)

Output

e)

Input

17.

How do you print out the last item on a list named shopping?

a)

shopping[0]

b)

shopping[last]

c)

shopping[-1]

d)

shopping[1]

18.

Given s = "Python", choose the Python code that DOES NOT give the output 6

a)

print(len(s))

b)

print(s.len())

c)

print(s.replace("Python","6"))

d)

print(len(s[ : len(s)] ))

19.

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

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

a)

nameList(1)

b)

nameList[4]

c)

nameList(4)

d)

nameList["1"]

20.

Which of these is a correct statement?

a)

List and tuples both are changeable.

b)

List is changeable whereas tuples are unchangeable.

c)

List and tuples both are unchangeable.

d)

List is unchangeable whereas tuples are changeable

21.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
22.

Mutable data stored in square brackets [ ]

a)

Containers

b)

List

c)

Tuple

d)

Variable Assignment

e)

Syntax

23.
What will the following lines of code print?
a)
A
b)
B C
c)
A C
d)
Nothing, it will return an error.
24.

The correct syntax of the len function for string x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

25.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

26.

If list=[10,20,30,40,50] then list[2]=35 will result

a)

[35,10,20,30,40,50]

b)

[10,20,30,40,50,35]

c)

[10,20,35,40,50]

d)

[10,35,30,40,50]

27.

data = "No Way!" The expression len(data) evaluates to:

a)

7

b)

9

c)

8

d)

6

28.
What will the lines of code print?
a)
A
b)
B C
c)
A B C
d)
A C
29.

Numbers that contain floating decimal points, such as 5.5, 5000.5, or even 2.509233

a)

Integer

b)

Float

c)

Value

d)

Error

e)

Fraction

30.

What output will this code produce?

a)

4

b)

2

c)

3

d)

5