wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Strings in python - Test

Total questions: 50

Worksheet time: 38mins

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.

Which of the operator can be used in Strings?

a)

+

b)

*

c)

Both of the above

d)

None of the above

3.

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

4.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

5.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

6.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

7.

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

a)

7

b)

9

c)

8

d)

6

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!)

15.
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
16.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
17.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
18.
What output will this code produce?
a)
4
b)
2
c)
3
d)
5
19.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17
20.
What output will this code produce?
a)
1
b)
3
c)
i
d)
0
21.

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

22.

Which of the following is not a valid string function?

a)

isalphanumeric

b)

isspace

c)

islower

d)

isalnum

23.
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!
24.
Which function takes a users input
a)
print()
b)
int()
c)
input()
d)
def
25.

data = "No Way!"


The expression len(data) evaluates to:

a)

8

b)

7

c)

6

26.

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

27.

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

a)

Capital

b)

Upper

c)

ConverttoUpper

d)

Capitalize

28.

str1='101'

x=int(str1)

z=x+400

print(z)

a)

101400

b)

x400

c)

501

d)

none of above

29.

fruit1="kiwi"

fruit2="strawberry"

print(len(fruit1))

print(len(fruit2))

a)

kiwi and strawberry

b)

4

10

c)

4 10

d)

410

30.

index of a string begins with

a)

1

b)

0

c)

a

d)

-1

31.

slicing string X="BOnVoyage"

print X[0:5]

a)

BOnVoy

b)

BOnVo

c)

oyage

d)

bonvo

32.

a="god help those who help themselves"

"help" in "a"

a)

true

b)

false

c)

wrong out put

d)

error

33.
What is printed?
cheer = "Go Eagles!"
print cheer[1:4]
a)
Go E
b)
o E
c)
"o E"
d)
nothing - there is an error
34.
What is printed?
cheer = "Go Eagles!"
print cheer[5:8]
a)
gle
b)
agle
c)
gles
d)
agles
35.
What is printed?
cheer = "Go Eagles!"
print cheer[7:]
a)
nothing - error
b)
s!
c)
es!
d)
Go Eagles
36.
What is printed?
cheer = "Go Eagles!"
print cheer[:5]
a)
Go Eag
b)
Go Ea
c)
Go E
d)
Go
37.
What is missing in the square braces?
cheer = "Go Eagles!"
print cheer[   ]
If the output is Eagle
a)
[4:9]
b)
[2:8]
c)
[3:7]
d)
[3:8]
38.
What is missing in the square braces?
cheer = "Go Eagles!"
print (cheer[   ] + cheer [  ] + cheer [  ])
If the output is Goggles
a)
0:2    5    5:9
b)
1:2     6   6:10
c)
0:1     5     5:9
d)
0:1     5     5:8
39.

"AB-CD-EF".partition('-') , the function returns the output

a)

('ABCD','-','EF')

b)

('AB', '-', 'CDEF')

c)

('AB', '-', 'CD-EF')

d)

None of the above

40.

Give the output of the following statements

>>> str='Hello World'

>>>str.istiltle()

a)

TRUE

b)

FALSE

41.

Mention the module which is imported in Regular Expression.

(a)  

42.

Which among the following functions returns the string that matched RE ?

(a)  

43.

Which function determines all substrings where the RE matches, and returns them as a list?

(a)  

44.

Which is the function that returns the tuple containing start and end positions?

(a)  

45.

Which meta character is used to specify that the previous character can be matched one or more times?

a)

[ ]

b)

+

c)

{ }

d)

*

46.

name =“humberside”

print(name[:2]

(a)  

47.

a=“Middlebury”

print(a[4:8])

(a)  

48.

x=””hello”+”world”

y=len(x)

print(y,x)

(a)  

49.

y=str(123)

x=”hello”*3

print(x,y)

(a)  

50.

word=”amazing”

word[-7:-3]

(a)