Test Series - python

Test Number 27/108

Q: 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
Solution: The first letter of the string is converted to uppercase and the others are converted to lowercase.
Q: 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
Solution: The first letter of the string is converted to uppercase and the others are converted to lowercase.
Q: What will be the output of the following Python code?

print("abcdef".center())
A. cd
B. abcdef
C. error
D. none of the mentioned
Solution: The function center() takes at least one parameter.
Q: 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
Solution: The entire string is printed when the argument passed to center() is less than the length of the string.
Q: 0
A. * abcdef *
B. * abcdef *
C. *abcdef *
D. * abcdef*
Solution: 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.
Q: 0
A. * abcdef *
B. * abcdef *
C. *abcdef *
D. * abcdef*
Solution: Padding is done towards the left-hand-side first when the final string is of odd length.
Q: 0
A. * abcde *
B. * abcde *
C. *abcde *
D. * abcde*
Solution: Padding is done towards the right-hand-side first when the final string is of even length.
Q: What will be the output of the following Python code?

print("abcdef".center(7, 1))
A. 1abcdef
B. abcdef1
C. abcdef
D. error
Solution: TypeError, the fill character must be a character, not an int.

You Have Score    /8