wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CPT C04 String functions

Total questions: 16

Worksheet time: 16mins

Name
Class
Date
1.

string="computing"

print(string[-3:])

What is the output?

(a)  

2.

string="computing"

The output of the program is COMPUTING.

What is the missing code (one line only)?

(a)  

3.

string="Computing Computing"

print(string.strip())

What is the output?

(a)  

4.

greeting="Hello, Computing!."

print(greeting.strip(" .,H"))

What is the output?

(a)  

5.

greeting="Computing Computing"

print(greeting.find("p",4))

What is the output?

(a)  

6.

greeting="Computing Computing"

print(greeting.find("m"))

(a)  

7.

greeting="Computing Computing"

print(greeting.find("k"))

(a)  

8.

greeting="Hello, Computing!."

print(greeting.strip("el.,H"))

(a)  

9.

my_school=["Pei","Hwa","Secondary","School"]

(a)  

print(my_school)

Output: Pei Hwa Secondary School

What is the missing code?

10.

my_dict={"School":"PH", "Area":"Sengkang"}

my_dict=" at ".join(my_dict.keys())

print(my_dict)

(a)  

11.

my_dict={"School":"PH", "Area":"Sengkang"}

my_dict=" at ".join(my_dict.values())

print(my_dict)

What is the output?

(a)  

12.

State the function to convert an ASCII code to character.

(a)  

13.

State the function to convert a character to an ASCII code.

(a)  

14.

words = "red-blue-green-yellow"

print(words.split("-"))

What is the output?

(a)  

15.

greeting = 'apple,orange,banana,grape'

print(greeting.split(',', 2))

(a)  

16.

sentence = 'one--two----three'

print(sentence.split('--'))

(a)