WorksheetsString in Python
Total questions: 36
Worksheet time: 19mins
Each item in a string has an "address" or index. The first index in a Python string is what?
0
1
a
A
Returning a range of characters (part of a string) is done using which syntax?
Slice
Splice
Cut
Select
What is the output from this code?
ell
llo
ello,
Hello
What is the output from this code?
, W
Wor
orl
lro
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
Evaluate the following expression:
"dog" < "Dog"
They are the same word
True
False
For strings, the + operator represents
Concatenation
Addition
Appending
Recantation
data = "No Way!" The expression len(data) evaluates to:
7
9
8
6
Which operator returns True if target string is somewhere in the search string; otherwise it returns False.
==
!=
in
is
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")
What will be the output?
name = "Dave"
print (name)
Dave
'Dave'
name
(name)
Is python an interpreter or compiler programming language?
Compiler
Interpreter
Which of the operator can be used in Strings?
+
*
Both of the above
None of the above
When we create a program to extract each alphabet from a given string, what is it known as?
Transpose
Traverse
Translate
Terminate
Which of the following is not a comparison operator?
<
>
==
!==
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
string="HELlo"
What will be the result of string.isupper()?
(a)
s1="Hello"
n1=10
print(s1+n1)
What is the error in this code?
Print statement not written in quotes
Numeric value not written in quotes
colon not written after the print statement
string cannot be added to a number
example = "helle"
print(example.rfind("e") )
-4
4
3
1
What will the below Python code will return?
If str1="save paper,save plants"
print(str1.find("save"))
It returns the first index position of the first occurance of "save" in the given string str1.
It returns the last index position of the last occurance of "save" in the given string str1.
It returns the last index position of the first occurance of "save" in the given string str1.
It returns the first index position of the last occurance of "save" in the given string str1.
