wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python String

Total questions: 21

Worksheet time: 11mins

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.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
3.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
4.
What output will this code produce?
a)
4
b)
2
c)
3
d)
5
5.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17
6.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
7.
What output will this code produce?
a)
1
b)
3
c)
i
d)
0
8.

word = "amazing"


For the given string if we run word[2:5] , what would the result be?

a)

mazi

b)

mazin

c)

azi

d)

azin

9.

Which of the following is not a valid string function?

a)

isalphanumeric

b)

isspace

c)

islower

d)

isalnum

10.

string="HELlo"

What will be the result of string.isupper()?

(a)  

11.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

12.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

13.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

14.

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

a)

7

b)

9

c)

8

d)

6

15.

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

a)

==

b)

!=

c)

in

d)

is

16.

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

17.

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

a)

Float

b)

Boolean

c)

Integer

d)

String

18.

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

19.

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!

20.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

21.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3