Python String capitalize() method
Python String capitalize() method
The string.capitalize() method in Python returns a copy of the string with only its first character capitalized.
Syntax
string.capitalize()
Parameter
NA
Return
This function returns a string where the first character is upper case.
Example 1
# Python String program explaining # the capitalize() method # passing the string value strVal = "hello world"; print("String value:",strVal) # capitalizing the first character of the String print ("After capitalizing the string:", strVal.capitalize())
Output
String value: hello world After capitalizing the string: Hello world
Example 2
# Python String program explaining # the capitalize() method #passing the first character as integer str = "21 is my roll no." # it will return a copy of the string as the first digit is integer n = str.capitalize() print (n)
Output
21 is my roll no.
Example 3
# Python program to demonstrate the # use of capitalize() function # passing the string value list = "the list of participants are as follow:" print(list.capitalize()) # capitalization of individual words to generate camel case name1 = "reema," name2 = "amar," name3 = "varun," name4 = "sukla" print(name1.capitalize() + name2.capitalize() + name3.capitalize()+name4.capitalize())
Output
The lists of participants are as follow: Reema,Amar,Varun,Sukla