Python String capitalize() method
The string.capitalize() method in Python returns a copy of the string with only its first character capitalized.
This function returns a string where the first character is upper case.
# 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())
String value: hello world After capitalizing the string: Hello world
# 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)
21 is my roll no.
# 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())
The lists of participants are as follow: Reema,Amar,Varun,Sukla