wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Mastering Python Strings

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What method would you use to convert a string to lowercase?

a)

.lower() or .toLowerCase()

b)

.upper()

c)

convertToLower()

d)

string.toLower()

2.

How do you concatenate two strings in Python?

a)

Use the '&' operator to combine strings.

b)

Use the '+' operator to concatenate strings.

c)

Use the '*' operator to concatenate strings.

d)

Use the 'concat()' method to join strings.

3.

What is the output of 'Hello, World!'[7:12]?

a)

lo, Wo

b)

World!

c)

World

d)

Hello

4.

Which method removes whitespace from the beginning and end of a string?

a)

removeSpaces

b)

trim

c)

clearWhitespace

d)

strip

5.

How can you check if a substring exists within a string?

a)

Use the 'in' operator in Python or 'contains' method in Java.

b)

Use the 'indexOf' method in C++

c)

Check the length of the string

d)

Use the 'find' method in Python

6.

What does the method .replace() do in a string?

a)

The .replace() method removes all whitespace from a string.

b)

The .replace() method converts a string to uppercase.

c)

The .replace() method splits a string into an array.

d)

The .replace() method replaces specified substrings in a string with new substrings.

7.

How do you access the first character of a string?

a)

Use string[0] to access the first character of a string.

b)

Use string.first() to get the first character.

c)

Access the first character with string.charAt(0).

d)

Retrieve the first character using string.slice(1).

8.

What is the result of 'Python' * 3?

a)

PythonPythonPython!

b)

PythonPythonPython

c)

PythonPython

d)

Python3

9.

How can you find the length of a string in Python?

a)

length(your_string)

b)

your_string.length()

c)

string.length(your_string)

d)

len(your_string)

10.

What does the method .split() do to a string?

a)

.split() removes all whitespace from a string.

b)

.split() divides a string into a list of substrings.

c)

.split() concatenates multiple strings into one.

d)

.split() converts a string to uppercase.