Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python strings

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

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

2.

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!

3.

What will the output be from the following code?

print("3+4")

a)

7

b)

34

c)

3+4

d)

SyntaxError

4.

What will the output be from the following code?

print("Hello world!")

a)

SyntaxError

b)

Hello world!

c)

"Hello world!"

d)

print(Hello world!)

5.

Which is the powerful function used for formatting strings?

a)

chr( )

b)

format( )

c)

title( )

d)

capitalize( )

6.

Which of the following will give "Simon" as output?

If str1="John,Simon,Aryan"

a)

print(str1[-7:-12])

b)

print(str1[-11:-7])

c)

print(str1[-11:-6])

d)

print(str1[-7:-11])

7.

Say s=”hello” what will be the return value of type(s)?

a)

STRING

b)

bool

c)

str

d)

String

8.

What will be the output of the following Python code?

print("D", end = ' ')

print("C", end = ' ')

print("B", end = ' ')

print("A", end = ' ')

a)

DCBA

b)

A,B,C,D

c)

D C B A

d)

D

C

B

A

9.

What will be the output of the “hello” +1+2+3?

a)

hello123

b)

hello

c)

Error

d)

hello6

10.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
11.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
12.

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

13.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

14.

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

a)

Float

b)

Boolean

c)

Integer

d)

String

15.
What will the output be from the following code?
Print("Hello world!")
a)
NameError
b)
Hello world!
c)
"Hello world"
d)
Print(Hello world!)
16.
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
17.
Which function takes a users input
a)
print()
b)
int()
c)
input()
d)
def
18.

What is the output from this code?

a)

ell

b)

llo

c)

ello,

d)

Hello

19.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
20.

If s='Sammy' what is the output of s[2:]

a)

'Sa'

b)

'Sam'

c)

'mmy'

d)

'ammy'