209). What will be the output of the following Python statement?
>>>"a"+"bc"
Show Answer
Correct Answer: abc
Notes:
Answer: d
Explanation: + operator is concatenation operator.
210). What will be the output of the following Python statement?
>>>"abcd"[2:]
Show Answer
Correct Answer: cd
Notes:
Answer: c
Explanation: Slice operation is performed on string.
211). The output of executing string.ascii_letters can also be achieved by:
>>>"abcd"[2:]
[A]string.ascii_lowercase_string.digits
[B]string.ascii_lowercase+string.ascii_uppercase
[C]string.letters
[D]string.lowercase_string.uppercase
Show Answer
Correct Answer: string.ascii_lowercase+string.ascii_uppercase
Notes:
Answer: b
Explanation: Execute in shell and check.
212). What will be the output of the following Python code?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
[A]olleh
[B]hello
[C]h
[D]o
Show Answer
Correct Answer: o
Notes:
Answer: d
Explanation: -1 corresponds to the last index.
213). What arithmetic operators cannot be used with strings?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
[A]+
[B]*
[C]–
[D]All of the mentioned
Show Answer
Correct Answer: –
Notes:
Answer: c
Explanation: + is used to concatenate and * is used to multiply strings.
214). What will be the output of the following Python code?
>>>print (r"\nhello")
[A]a new line and hello
[B]\nhello
[C]the letter r and then hello
[D]error
Show Answer
Correct Answer: \nhello
Notes:
Answer: b
Explanation: When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw string and the escape sequences such as \n are not converted.
215). What will be the output of the following Python statement?
>>>print('new' 'line')
[A]Error
[B]Output equivalent to print ‘new\nline’
[C]newline
[D]new line
Show Answer
Correct Answer: newline
Notes:
Answer: c
Explanation: String literal separated by whitespace are allowed. They are concatenated.
216). What will be the output of the following Python statement?
>>> print('x\97\x98')
[A]Error
[B] 97
98
[C]x\97
[D]\x97\x98
Show Answer
Correct Answer: x\97
Notes:
Answer: c
Explanation: \x is an escape sequence that means the following 2 digits are a hexadecimal number encoding a character.
217). What will be the output of the following Python code?
>>>str1="helloworld"
>>>str1[::-1]
[A]dlrowolleh
[B]hello
[C]world
[D]helloworld
Show Answer
Correct Answer: dlrowolleh
Notes:
Answer: a
Explanation: Execute in shell to verify.
218). What will be the output of the following Python code?
print(0xA + 0xB + 0xC)
[A]0xA0xB0xC
[B]Error
[C]0x22
[D]33
Show Answer
Correct Answer: 33
Notes:
Answer: d
Explanation: 0xA and 0xB and 0xC are hexadecimal integer literals representing the decimal values 10, 11 and 12 respectively. There sum is 33.