wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

String Manipulation (Python)

Total questions: 17

Worksheet time: 13mins

Name
Class
Date
1.

how we store string value in variable?

a)

'string'

b)

"string"

c)

%string%

d)

#sring#

2.

index of a string begins with

a)

1

b)

0

c)

a

d)

-1

3.

The pseudocode below assigns two strings to two variables:

title = "computer science"

level = "gcse"

What would the Python code: len(level) return?

a)

2

b)

3

c)

4

d)

1

4.

The pseudocode below assigns two strings to two variables:

title = "computer science"

level = "gcse"

What is title[0]?

a)

'c'

b)

'o'

c)

'g'

d)

An error

5.

The pseudocode below assigns two strings to two variables:

title = "computer science"

level = "gcse"

What is title[4]?

a)

'p'

b)

'u'

c)

't'

d)

An error

6.

string = "abcdef"

What is index of "f" ?

(a)  

7.

string = "Computer Science"

What is string[0:8] ?

(a)  

8.

Sequences of characters within a string can be accessed by taking a string ______ using [ ]

a)

slice

b)

cut

c)

chop

d)

substring

9.

string1 = "Monty"

string2 = "Python"

string3 = string1 + string2

What is value of string3?

a)

Monty Python

b)

MontyPython

c)

Monty+Python

d)

string3

10.
What output will this code produce?
a)
4
b)
2
c)
3
d)
5
11.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
12.

What does the isdigit() function do in Python?

a)

Returns True if all the characters in the string are in capital letters

b)

Returns True if all the characters in the string are in small letters

c)

Returns True if the string contains only spaces

d)

Returns True if all the characters in the string are digits

13.

What is the output of the code fragment: print('hello'*3, str(123))?

a)

hellohellohello, 123

b)

hellohellohello, hellohellohello

c)

hellohellohello, 123123123

d)

hellohellohello, hello

14.

Which of these will print the length of a string

a)

print(len("a string"))

b)

print("a string".len())

c)

print(length("a string"))

d)

x = len.string()

15.

Which code would get the characters from position 2 to position 5 (not included).

a)

x = txt[2:5]

b)

x = txt[1:5]

c)

x = txt[1:4]

d)

x = txt[0[:4]

16.

Convert the value of txt to upper case.

a)

x = txt.upper()

b)

x = txt.lower()

c)

x = upper(txt)

d)

x = upper.txt()

17.

Replace the character H with a J

a)

x = txt.replace("H", "J")

b)

x = txt.replace("J", "H")

c)

x = replace ("H", "J")

d)

x = txt.replace(H,J)