What will be the output of the following Python code?
print("abc. DEF".capitalize())
print("abc. DEF".capitalize())
A. Abc. def
B. abc. def
C. Abc. Def
D. ABC. DEF
Answer: Option A
Solution (By Examveda Team)
The `capitalize()` method in Python converts the first character of a string to uppercase and the rest of the characters to lowercase.Given Code: `print("abc. DEF".capitalize())`
1. The first character `a` is converted to uppercase, resulting in `A`.
2. All other characters, including the uppercase `DEF`, are converted to lowercase, resulting in `bc. def`.
Final Output: `Abc. def`
Explanation:
The capitalize() method in Python performs the following:
Converts the first character of the string to uppercase (if it is a letter).
Converts all other characters in the string to lowercase.
So, "abc. DEF".capitalize() processes the string as:
The first character 'a' is converted to uppercase: 'A'.
All other characters are converted to lowercase: 'bc. def'.
Output:
Abc. def