wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Essentials_FT_Batch 3

Total questions: 20

Worksheet time: 12mins

Name
Class
Date
1.

Assume the following list definition:

a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']

a)

print(a[4::-2])

b)

a[:] is a

c)

max(a[2:4] + ['grault'])

d)

print(a[-5:-3])

2.

List a is defined as follows:

a = ['a', 'b', 'c']

Which of the following statements adds 'd' and 'e' to the end of a, so that it then equals ['a', 'b', 'c', 'd', 'e']:

a)

a += 'de'

b)

a += ['d', 'e']

c)

a.append(['d', 'e'])

d)

a[len(a):] = ['d', 'e']

e)

a.extend(['d', 'e'])

3.

names1 = ['Amir', 'Barry', 'Chales', 'Dao']

loc = names1.index("Edward")

print(loc)

a)

-1

b)

0

c)

4

d)

Edward

e)

An exception is thrown

4.

Which of the following are true of Python lists?

a)

These represent the same list:['a', 'b', 'c'] ['c', 'a', 'b']

b)

A given object may appear in a list more than once

c)

All elements in a list must be of the same type

d)

A list may contain any type of object except another list

e)

There is no conceptual limit to the size of a list

5.

You have a list a defined as follows:

a = [1, 2, 7, 8]

Write a Python statement using slice assignment that will fill in the missing values so that a equals [1, 2, 3, 4, 5, 6, 7, 8].

(a)  

6.

Same nested list as the previous question:

x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']

What expression returns the list ['baz', 2.718]?

(a)  

7.

What is the purpose of the print() function in Python?

a)

To display output to the console

b)

To read user input

c)

To create a variable

d)

To define a function

8.

Which symbol is used to create a list in Python?

a)

( )

b)

[ ]

c)

{ }

d)

< >

9.

Which of the following is a valid variable name in Python?

a)

1st_variable

b)

my-variable

c)

myVariable

d)

my variable

10.

How do you start a function definition in Python?

a)

function myFunction():

b)

def myFunction():

c)

create myFunction():

d)

myFunction():

11.

What is the output of the following code? x = 5 print(x * 2)

a)

10

b)

5

c)

25

d)

Error

12.

How do you start writing a for loop in Python?

a)

for each i in x:

b)

for i = 1 to x:

c)

for i in x:

d)

for i > x:

13.

What would be the value of ‘new_score’ after running this code:
score = 44
total = 1

new_score = score * 2

a)

88

b)

44

c)

45

d)

22

14.

What is the output of the following code? print("Hello " * 3)

a)

Hello Hello Hello

b)

Hello 3

c)

Hello Hello Hello 3

d)

Error

15.

Which operator is used to check equality in Python?

a)

==

b)

=

c)

===

d)

!=

16.

What will be the output of this code? x = [1, 2, 3] print(len(x))

a)

3

b)

2

c)

1

d)

Error

17.

What will the following code output? x = "Hello" print(x[1])

a)

H

b)

e

c)

Hello

d)

Error

18.

What sort of error occurs when the program runs but you do not get the correct answer you expected?

a)

Answer Error

b)

Syntax Error

c)

Run-time Error

d)

Logical Error

19.

what does this code display:
counter = 1

while counter <4:

                print (counter)

counter = counter + 1

a)

1 2 3 4

b)

1 2 3

c)

0 1 2 3

d)

0 1 2 3 4

20.

Who developed the Python language?

a)

Zim Den

b)

Guido van Rossum

c)

Niene Stom

d)

Wick van Rossum