Test Series - python

Test Number 23/108

Q: What will be the output of the following Python statement?

>>>"a"+"bc"
A. ab
B. a
C. bc
D. abc
Solution: + operator is concatenation operator.
Q: What will be the output of the following Python statement?

>>>"abcd"[2:]
A. ab
B. a
C. cd
D. dc
Solution: Slice operation is performed on string.
Q: The output of executing string.ascii_letters can also be achieved by:
A. string.ascii_lowercase_string.digits
B. string.ascii_lowercase+string.ascii_uppercase
C. string.letters
D. string.lowercase_string.uppercase
Solution: Execute in shell and check.
Q: What arithmetic operators cannot be used with strings?
A. +
B. *
C. 
D. All of the mentioned
Solution: + is used to concatenate and * is used to multiply strings.
Q: What will be the output of the following Python code?

>>>print (r"
hello")
A. a new line and hello
B.  hello
C. the letter r and then hello
D. error
Solution: When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw string and the escape sequences such as 
 are not converted.
Q: What will be the output of the following Python code?

>>>str1="helloworld"
>>>str1[::-1]
A. dlrowolleh
B. hello
C. world
D. helloworld
Solution: Execute in shell to verify.
Q:  What will be the output of the following Python code?

print(0xA + 0xB + 0xC)
A. 0xA0xB0xC
B. Error
C. 0x22
D. 33
Solution: 0xA and 0xB and 0xC are hexadecimal integer literals representing the decimal values 10, 11 and 12 respectively. There sum is 33.

You Have Score    /7