ExamVeda
Login
Home
Introduction to Python
?

What will be the output of the following Python code?
print("abc. DEF".capitalize())

Answer & Solution
Correct Answer: Option A
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`
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
BANTI PATIL
BANTI PATIL 2 years ago
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