WorksheetsPYTHON-STRINGS
Total questions: 50
Worksheet time: 29mins
France
Wales
Wales
France
Ireland
What output will this code produce?
['blue', 'green', 'red', 'yellow']
['blue', 'red', 'yellow']
['yellow', 'red', 'green']
['yellow', 'red', 'blue']
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 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!)
What would this print?
print("Hello" + "world" + "today")
print("Hello world!\nHello world!")
Hello world!
Which operator returns True if target string is somewhere in the search string; otherwise it returns False.
==
!=
is
in
+ operator represents data = "No Way!"
The expression len(data) evaluates to:
8
7
6
print("" in "APCSP")
Which of the operator can be used in Strings?
+
*
Both of the above
None of the above
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
word = "amazing"
For the given string if we run word[2:5:2] what does 2 mean in this function?
It will pick only second alphabet
It will pick only two alphabets
It will pick every alternate alphabet
It will pick first two alphabets
Which of the following is not a valid string function?
isalphanumeric
isspace
islower
isalnum
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
Which brackets are used for Lists?
( )
[ ]
{ }
None of the above
