In this tutorial, We will see the python string capitalize() method with examples.
capitalize() Method
The capitalize() method is one of the methods in a python string. The capitalize() method is used for string conversion.
- The capitalize() method converts the string first character to uppercase and the rest of the characters to lowercase.
- If the string first character is in the already upper case and the rest of the characters are in the lower case then applying the capitalize() method will not bring any change.
Syntax of Python string capitalize() method
This is the syntax of the python string capitalize() method.
string.capitalize()
Example of Python string capitalize() method
#Example 1 text = "PYTHON IS A PROGRAMMING LANGUAGE" print(text.capitalize()) #output : Python is a programming language
#Example 2 text = "convert into capitalize, python capitalize method" print(text.capitalize()) #output: Convert into capitalize, python capitalize method #Exmaple 3 message = "hello WORLD!" msg = message.capitalize() print(msg) #output: Hello world!
Program: Take a string from user input and convert string first character into capital case and rest of the character into lower case.
message = input("Enter the message" msg = message.capitalize() print(msg)
Related Posts