wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Strings

Total questions: 10

Worksheet time: 12mins

Name
Class
Date
1.

Which of the following statement are true?

Strings....

a)

are enclosed by single quotation marks only

b)

are enclosed by double quotation marks only

c)

Can include letters, digits, special characters, and spaces

d)

can include letters, digits, special characters, but not spaces

2.

Select the correct output of the following String operations

strOne = str("pynative")

strTwo = "pynative"

print(strOne == strTwo)

print(strOne is strTwo)

a)

False False

b)

True True

c)

True False

d)

False True

3.

What is the output of the following string operations?

str = "My salary is 7000";

print(str.isalnum())

a)

True

b)

False

4.

Which method should I use to convert String "welcome to the beautiful world of python" to "Welcome To The Beautiful World Of Python"

a)

capitalize()

b)

title()

c)

upper()

d)

lower()

5.

What is the output of the following code?

str1 = "My salary is 7000";

str2 = "7000"

print(str1.isdigit())

print(str2.isdigit())

a)

False

True

b)

False

False

c)

True

False

d)

True

True

6.

Guess the correct output of the following code.

str1 = "PYnative"

print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])

a)

PYn PYnat ive PYnativ vitanYP

b)

Yna PYnat tive PYnativ vitanYP

c)

Yna PYnat tive PYnativ PYnativ

7.

Select the correct output of the following String operations

str = "my name is James bond";

print (str.capitalize())

a)

My Name Is James Bond

b)

TypeError: unsupported operand type(s) for * or pow(): 'str' and 'int'

c)

My name is james bond

d)

mY NAME IS JAMES BOND

8.

Select the correct output of the following String operations

str1 = "my isname isisis jameis isis bond";

sub = "is";

print(str1.count(sub, 4))

a)

5

b)

6

c)

7

d)

8

9.

Select the correct output of the following String operations

str1 = 'Welcome'

print (str1[:6] + ' PYnative')

a)

Welcome PYnative

b)

WelcomPYnative

c)

Welcom PYnative

d)

WelcomePYnative

10.

Strings are immutable in Python, which means a string cannot be modified.

a)

True

b)

False