If S='python language' is a Python string, which of the following command will…
2023
If S='python language' is a Python string, which of the following command will display the following output with 'P' in upper case and remaining in lower case ?
- A.
print(S.upper()) / print(S.upper())
- B.
print(S.title()) / print(S.title())
- C.
print(S.capitalize()) / print(S.capitalize())
- D.
print(S.sentence()) / print(S.sentence())
Attempted by 1700 students.
Show answer & explanation
Correct answer: C
Answer: Use the string method that makes the first character uppercase and the rest lowercase. Correct command: print(S.capitalize()) Example output for S = 'python language': print(S.capitalize()) -> Python language Why this works: capitalize() makes the first character of the entire string uppercase and converts all other characters to lowercase. Why other methods are incorrect: upper() converts every character to uppercase (e.g., 'PYTHON LANGUAGE'), title() capitalizes the first letter of each word (e.g., 'Python Language'), and sentence() is not a valid string method and will raise an error.