Capitalize first character of a string in Python

You can convert first character in upper case of a string into upper case with using capitalize() function. We do call capitalize function on a string object. It makes first character uppercase and rest string in lowercase. Example of capitalize method is mentioned below: Code


str = "hello world"
capitalized = str[0].upper() + str[1:]
print(capitalized)  # Output: Hello world