249). What will be the output of the following Python code?
print("abc DEF".capitalize())
[A]abc def
[B]ABC DEF
[C]Abc def
[D]Abc Def
Show Answer
Correct Answer: Abc def
Notes:
Answer: c
Explanation: The first letter of the string is converted to uppercase and the others are converted to lowercase.
250). What will be the output of the following Python code?
print("abc. DEF".capitalize())
[A]abc. def
[B]ABC. DEF
[C]Abc. def
[D]Abc. Def
Show Answer
Correct Answer: Abc. def
Notes:
Answer: c
Explanation: The first letter of the string is converted to uppercase and the others are converted to lowercase.
251). What will be the output of the following Python code?
print("abcdef".center())
[A]cd
[B]abcdef
[C]error
[D]none of the mentioned
Show Answer
Correct Answer: error
Notes:
Answer: c
Explanation: The function center() takes at least one parameter.
252). What will be the output of the following Python code?
print("abcdef".center(0))
[A]cd
[B]abcdef
[C]error
[D]none of the mentioned
Show Answer
Correct Answer: abcdef
Notes:
Answer: b
Explanation: The entire string is printed when the argument passed to center() is less than the length of the string.
253). What will be the output of the following Python code?
print("abcdef".center(0))
[A]cd
[B]abcdef
[C]error
[D]none of the mentioned
Show Answer
Correct Answer: abcdef
Notes:
Answer: b
Explanation: The entire string is printed when the argument passed to center() is less than the length of the string.
254). What will be the output of the following Python code?
print('*', "abcdef".center(7), '*')
[A]* abcdef *
[B]* abcdef *
[C]*abcdef *
[D]* abcdef*
Show Answer
Correct Answer: * abcdef *
Notes:
Answer: b
Explanation: Padding is done towards the left-hand-side first when the final string is of odd length. Extra spaces are present since we haven’t overridden the value of sep.
255). What will be the output of the following Python code?
print('*', "abcdef".center(7), '*', sep='')
[A]* abcdef *
[B]* abcdef *
[C]*abcdef *
[D]* abcdef*
Show Answer
Correct Answer: * abcdef*
Notes:
Answer: d
Explanation: Padding is done towards the left-hand-side first when the final string is of odd length.
256). What will be the output of the following Python code?
print('*', "abcde".center(6), '*', sep='')
[A]* abcde *
[B]* abcde *
[C]*abcde *
[D]* abcde*
Show Answer
Correct Answer: *abcde *
Notes:
Answer: c
Explanation: Padding is done towards the right-hand-side first when the final string is of even length.
257). What will be the output of the following Python code?
print("abcdef".center(7, 1))
[A]1abcdef
[B]abcdef1
[C]abcdef
[D]error
Show Answer
Correct Answer: error
Notes:
Answer: d
Explanation: TypeError, the fill character must be a character, not an int.
258). What will be the output of the following Python code?
print("abcdef".center(7, '1'))
[A]1abcdef
[B]abcdef1
[C]abcdef
[D]error
Show Answer
Correct Answer: 1abcdef
Notes:
Answer: a
Explanation: The character ‘1’ is used for padding instead of a space.
259). What will be the output of the following Python code?
print("abcdef".center(10, '12'))
[A]12abcdef12
[B]abcdef1212
[C]1212abcdef
[D]error
Show Answer
Correct Answer: error
Notes:
Answer: d
Explanation: The fill character must be exactly one character long.