Font size
WorksheetsStrings in python - Test
Total questions: 50
Worksheet time: 38mins
What letter will be printed on the screen after running this code:
e
x
t
Nothing prints
Which of the operator can be used in Strings?
+
*
Both of the above
None of the above
Python accepts single ('), double (") and triple (''' or """) quotes to denote strings. Which of the following is NOT acceptable Python syntax?
print('Hello World')
print("Hello World")
print('Hello World")
print(""'Hello World'"")
What is printed by the following statement?
print("P" not in "APCSP")
True
False
Error
What is printed by the following statement?
print("A" in "APCSP")
True
False
Error
For strings, the + operator represents
Concatenation
Addition
Appending
Recantation
data = "No Way!" The expression len(data) evaluates to:
7
9
8
6
What syntax can you use to insert a line break between strings so that they appear over multiple lines?
\l
/
\\n
\n
Which is the most appropriate data type for: "13th December"
Float
Boolean
Integer
String
What will the output be from the following code?
print("Hello world!" * 2)
TypeError
Hello world world!
Hello world!Hello world!
Hello world! * 2
What will the output be from the following code?
print("Hello world!\nHello world!")
Hello world! Hello world!
Hello world!
Hello world!
SyntaxError
Hello world!
What will the output be from the following code?
print("3+4")
7
34
3+4
SyntaxError
print("12"*3)
What would this print?
121212
36
24
12*3
What will the output be from the following code?
print("Hello world!")
SyntaxError
Hello world!
"Hello world!"
print(Hello world!)
print("Hello" + "world" + "today")
word = "amazing"
For the given string if we run word[2:5] , what would the result be?
mazi
mazin
azi
azin
Which of the following is not a valid string function?
isalphanumeric
isspace
islower
isalnum
print("Hello world!\nHello world!")
Hello world!
data = "No Way!"
The expression len(data) evaluates to:
8
7
6
word = "amazing"
For the given string if we run word[2:5] what does it mean?
It will extract alphabets from index 2 to index 4
It will extract alphabets from index 2 to index 5
It will extract alphabets from position 2 to position 4
It will extract alphabets from position 2 to position 5
Which method is used to convert a given string in Capital letters?
Capital
Upper
ConverttoUpper
Capitalize
str1='101'
x=int(str1)
z=x+400
print(z)
101400
x400
501
none of above
fruit1="kiwi"
fruit2="strawberry"
print(len(fruit1))
print(len(fruit2))
kiwi and strawberry
4
10
4 10
410
index of a string begins with
1
0
a
-1
slicing string X="BOnVoyage"
print X[0:5]
BOnVoy
BOnVo
oyage
bonvo
a="god help those who help themselves"
"help" in "a"
true
false
wrong out put
error
cheer = "Go Eagles!"
print cheer[1:4]
cheer = "Go Eagles!"
print cheer[5:8]
cheer = "Go Eagles!"
print cheer[7:]
cheer = "Go Eagles!"
print cheer[:5]
cheer = "Go Eagles!"
print cheer[ ]
If the output is Eagle
cheer = "Go Eagles!"
print (cheer[ ] + cheer [ ] + cheer [ ])
If the output is Goggles
"AB-CD-EF".partition('-') , the function returns the output
('ABCD','-','EF')
('AB', '-', 'CDEF')
('AB', '-', 'CD-EF')
None of the above
Give the output of the following statements
>>> str='Hello World'
>>>str.istiltle()
TRUE
FALSE
Mention the module which is imported in Regular Expression.
(a)
Which among the following functions returns the string that matched RE ?
(a)
Which function determines all substrings where the RE matches, and returns them as a list?
(a)
Which is the function that returns the tuple containing start and end positions?
(a)
Which meta character is used to specify that the previous character can be matched one or more times?
[ ]
+
{ }
*
name =“humberside”
print(name[:2]
(a)
a=“Middlebury”
print(a[4:8])
(a)
x=””hello”+”world”
y=len(x)
print(y,x)
(a)
y=str(123)
x=”hello”*3
print(x,y)
(a)
word=”amazing”
word[-7:-3]
(a)
