WorksheetsPython Strings
Total questions: 10
Worksheet time: 12mins
Which of the following statement are true?
Strings....
are enclosed by single quotation marks only
are enclosed by double quotation marks only
Can include letters, digits, special characters, and spaces
can include letters, digits, special characters, but not spaces
Select the correct output of the following String operations
strOne = str("pynative")
strTwo = "pynative"
print(strOne == strTwo)
print(strOne is strTwo)
False False
True True
True False
False True
What is the output of the following string operations?
str = "My salary is 7000";
print(str.isalnum())
True
False
Which method should I use to convert String "welcome to the beautiful world of python" to "Welcome To The Beautiful World Of Python"
capitalize()
title()
upper()
lower()
What is the output of the following code?
str1 = "My salary is 7000";
str2 = "7000"
print(str1.isdigit())
print(str2.isdigit())
False
True
False
False
True
False
True
True
Guess the correct output of the following code.
str1 = "PYnative"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
PYn PYnat ive PYnativ vitanYP
Yna PYnat tive PYnativ vitanYP
Yna PYnat tive PYnativ PYnativ
Select the correct output of the following String operations
str = "my name is James bond";
print (str.capitalize())
My Name Is James Bond
TypeError: unsupported operand type(s) for * or pow(): 'str' and 'int'
My name is james bond
mY NAME IS JAMES BOND
Select the correct output of the following String operations
str1 = "my isname isisis jameis isis bond";
sub = "is";
print(str1.count(sub, 4))
5
6
7
8
Select the correct output of the following String operations
str1 = 'Welcome'
print (str1[:6] + ' PYnative')
Welcome PYnative
WelcomPYnative
Welcom PYnative
WelcomePYnative
Strings are immutable in Python, which means a string cannot be modified.
True
False
