What will be the output of the following Python statement?
a) a
b) bc
c) bca
d) abc
Explanation: + operator is concatenation operator.
What will be the output of the following Python statement?
a) a
b) ab
c) cd
d) dc
Explanation: Slice operation is performed on string.
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
Explanation: Execute in shell and check.
What will be the output of the following Python code?
a) olleh
b) hello
c) h
d) o
Explanation: -1 corresponds to the last index.
What arithmetic operators cannot be used with strings?
a) +
b) *
c) –
d) All of these
Explanation: + is used to concatenate and * is used to multiply strings.
What will be the output of the following Python code?
a) a new line and hello
b) \nhello
c) the letter r and then hello
d) error
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.