Python String capitalize() MethodPython Functions

Difficulty Level:
Difficulty Level:

The capitalize() function turns the first letter of the string to uppercase and the other letters to lowercase.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

str = "she is good at Math"
print (str.capitalize())

str = " she likes watching TV"
print (str.capitalize())

Output:

She is good at math
 she likes watching tv

Syntax

str.capitalize()

Parameters

The method doesn’t take any parameters.

Return Value

It returns a string with the first letter capitalized and all other characters lowercased.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us