Q: What will be the output of the following Python code? print("abc DEF".capitalize())
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())
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())
Solution: The function center() takes at least one parameter.
Q: What will be the output of the following Python code? print("abcdef".center(0))
Solution: The entire string is printed when the argument passed to center() is less than the length of the string.
Q: 0
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
Solution: Padding is done towards the left-hand-side first when the final string is of odd length.
Q: 0
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))
Solution: TypeError, the fill character must be a character, not an int.
You Have Score    | /8 |