wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Strings

Total questions: 14

Worksheet time: 7mins

Name
Class
Date
1.

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'"")

2.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

3.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

4.

Evaluate the following expression:

"dog" < "Dog"

a)

They are the same word

b)

True

c)

False

5.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

6.

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

a)

7

b)

9

c)

8

d)

6

7.

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

a)

==

b)

!=

c)

in

d)

is

8.

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

9.

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

a)

Float

b)

Boolean

c)

Integer

d)

String

10.

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

11.

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!

12.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

13.

print("12"*3)

What would this print?

a)

121212

b)

36

c)

24

d)

12*3

14.

What will the output be from the following code?

print("Hello world!")

a)

SyntaxError

b)

Hello world!

c)

"Hello world!"

d)

print(Hello world!)