wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

STRING HANDLING IN PYTHON

Total questions: 24

Worksheet time: 14mins

Name
Class
Date
1.

One of the following functions is not used with Python String

a)

Split

b)

Remove

c)

print

d)

Replace

2.

Choose the correct syntax of the split function:

a)

x.split[]

b)

split(x)

c)

x.split(",", 3)

d)

X.SPLIT(",", 3)

3.

The correct syntax of the len function for string x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

4.

The correct syntax for converting the string x to uppercase is :

a)

X.upper()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

5.

To remove the spaces present at start and end of the string, you can use

a)

split()

b)

len()

c)

strip()

d)

remove()

6.

Let x= "Python", the output of print(x.upper()) is

a)

python

b)

PYTHON

c)

_PYTHON

d)

"PYTHON"

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

For string symbol + means........................

a)

addition

b)

swapp

c)

concatenation

d)

multiplication

9.

index of a string begins with

a)

1

b)

0

c)

a

d)

-1

10.

slicing string X="BOnVoyage"

print X[0:5]

a)

BOnVoy

b)

BOnVo

c)

oyage

d)

bonvo

11.

Slicing string

x="BOnvoyage

print(x[4: ])

a)

BOnvo

b)

bonvo

c)

voyage

d)

VOYAGE

12.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
13.

Returning a range of characters (part of a string) is done using which syntax?

a)

Slice

b)

Splice

c)

Cut

d)

Select

14.

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

15.

What is printed by the following statement?

print("P" not in "APCSP")

a)

True

b)

False

c)

Error

16.

What is printed by the following statement?

print("A" in "APCSP")

a)

True

b)

False

c)

Error

17.

Evaluate the following expression:

"dog" < "Dog"

a)

They are the same word

b)

True

c)

False

18.

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

a)

==

b)

!=

c)

in

d)

is

19.

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

20.
Which function takes a users input
a)
print()
b)
int()
c)
input()
d)
def
21.
A data type consisting of numbers, letters and symbols.
a)
String
b)
Integer
c)
Float
d)
Boolean
22.

True or False: Python automatically adds spaces when we add Strings together.

a)

True

b)

False

23.

True or False: Subtracting Strings removes the letters of one from the other.

a)

True

b)

False

24.
Today I learnt…
a)
A little
b)
A lot
c)
Nothing
d)
I have no idea, I'm so confused…