wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON-STRINGS

Total questions: 50

Worksheet time: 29mins

Name
Class
Date
1.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
2.
What is the position of the name "Robert" in the following list:
a)
0
b)
1
c)
2
d)
3
3.
What does the APPEND procedure do in the following code:
a)
Adds Liverpool to the beginning of the list
b)
Replaces Bristol with Liverpool
c)
Replaces Manchester with Liverpool
d)
Adds Liverpool to the end of the list
4.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
5.
Each item in a list has an "address" or index. The first index in a Python list is what?
a)
0
b)
1
c)
a
d)
A
6.
What output will this code produce?
a)
['France', 'Wales', 'England']
France
b)
['France', 'Wales', 'England']
Wales
c)
France, Wales, England
Wales
d)
France  Wales  England
France
7.
What output will this code produce?
a)
['France', 'Wales', 'England']
Ireland
b)
['France', 'Ireland', 'England']
c)
['France', 'Ireland', 'Wales', 'England']
d)
['Ireland', 'Wales', 'England']
8.
In a list called "players" if you wanted to delete the item with an index of 3 which of the following examples of code would be correct?
a)
players.pop[3]
b)
players.delete(3)
c)
players.remove(3)
d)
players.pop(3)
9.
In a list called "players", if you wanted to add a player called "Bob" to the list, which of the following examples of code would be correct?
a)
players.add("Bob")
b)
player.append("Bob")
c)
players.append("Bob")
d)
players.addend("Bob")
10.
If you want to create an empty list called colours, which of the following pieces of code is correct?
a)
colours = [ ]
b)
colours = ( )
c)
colours = { }
d)
colors = [ ]
11.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
12.
What output will this code produce?
a)
4
b)
2
c)
3
d)
5
13.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17
14.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
15.
What output will this code produce?
a)
1
b)
3
c)
i
d)
0
16.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
17.
What output will this code produce?
a)
red
b)
['blue', 'green', 'red']
c)
['red', 'green', 'blue']
d)
error
18.
What output will this code produce?
a)
['blue', 'green', 'red', 'yellow']
b)
['blue', 'red', 'yellow']
c)
['yellow', 'red', 'green']
d)
['yellow', 'red', 'blue']
19.

What output will this code produce?

a)

['blue', 'green', 'red', 'yellow']

b)

['blue', 'red', 'yellow']

c)

['yellow', 'red', 'green']

d)

['yellow', 'red', 'blue']

20.

Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?

a)

print('Hello World')

b)

print("Hello World")

c)

print('Hello World")

d)

print(""'Hello World'"")

21.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

22.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

23.

Evaluate the following expression:

"dog" < "Dog"

a)

They are the same word

b)

True

c)

False

24.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

25.

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

a)

7

b)

9

c)

8

d)

6

26.

Which operator returns True if target string is somewhere in the search string; otherwise it returns False.

a)

==

b)

!=

c)

in

d)

is

27.

What syntax can you use to insert a line break between strings so that they appear over multiple lines?

a)

\l

b)

/

c)

\\n

d)

\n

28.

Which is the most appropriate data type for: "13th December"

a)

Float

b)

Boolean

c)

Integer

d)

String

29.

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

30.

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)

SyntaxError

d)

Hello world!

31.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

32.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

33.

What will the output be from the following code?

print("Hello world!")

a)

SyntaxError

b)

Hello world!

c)

"Hello world!"

d)

print(Hello world!)

34.
print("12"*3)
What would this print?
a)
36
b)
121212
c)
24
d)
12*3
35.
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
36.
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)
SyntaxError
d)
Hello world!
37.
Which function takes a users input
a)
print()
b)
int()
c)
input()
d)
def
38.
Which is the most appropriate data type for: "13th December"
a)
Float
b)
Boolean
c)
Integer
d)
String
39.

Which operator returns True if target string is somewhere in the search string; otherwise it returns False.

a)

==

b)

!=

c)

is

d)

in

40.
For strings, the + operator represents 
a)
Concatenation
b)
Addition
c)
Appending
d)
Recantation 
41.

data = "No Way!"


The expression len(data) evaluates to:

a)

8

b)

7

c)

6

42.
What is printed by the following statement?
print("" in "APCSP")
a)
True
b)
False
c)
Error
43.
Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?
a)
print('Hello World')
b)
print("Hello World")
c)
print('Hello World")
d)
print(""'Hello World'"")
44.

Which of the operator can be used in Strings?

a)

+

b)

*

c)

Both of the above

d)

None of the above

45.

word = "amazing"

For the given string if we run word[2:5] what does it mean?

a)

It will extract alphabets from index 2 to index 4

b)

It will extract alphabets from index 2 to index 5

c)

It will extract alphabets from position 2 to position 4

d)

It will extract alphabets from position 2 to position 5

46.

Which method is used to convert a given string in Capital letters?

a)

Capital

b)

Upper

c)

ConverttoUpper

d)

Capitalize

47.

word = "amazing"

For the given string if we run word[2:5:2] what does 2 mean in this function?

a)

It will pick only second alphabet

b)

It will pick only two alphabets

c)

It will pick every alternate alphabet

d)

It will pick first two alphabets

48.

Which of the following is not a valid string function?

a)

isalphanumeric

b)

isspace

c)

islower

d)

isalnum

49.

s1="Hello"

n1=10

print(s1+n1)

What is the error in this code?

a)

Print statement not written in quotes

b)

Numeric value not written in quotes

c)

colon not written after the print statement

d)

string cannot be added to a number

50.

Which brackets are used for Lists?

a)

( )

b)

[ ]

c)

{ }

d)

None of the above