{"id":24442,"date":"2021-10-17T18:33:41","date_gmt":"2021-10-17T13:03:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=24442"},"modified":"2021-11-05T19:23:37","modified_gmt":"2021-11-05T13:53:37","slug":"program-for-python-string-capitalize-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-python-string-capitalize-function\/","title":{"rendered":"Program for Python String capitalize() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for hypot() Function<\/a> The capitalize() method returns a string in which the first character is upper case and the remaining characters are lower case.<\/p>\n Non-letters are not capitalized by the string capitalize function.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong> This function doesn’t have any parameters.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Go through our tutorial and learn about various Python String Method Examples<\/a> and learn how to apply the knowledge while dealing with strings.<\/p>\n In the previous article, we have discussed Python Program for hypot() Function capitalize() Function in Python: The capitalize() method returns a string in which the first character is upper case and the remaining characters are lower case. Non-letters are not capitalized by the string capitalize function. Syntax: string.capitalize() Parameters: This function doesn’t have any parameters. …<\/p>\n
\ncapitalize() Function in Python:<\/strong><\/p>\nstring.capitalize()<\/pre>\n
Given first string = \"hello this is BTECHGEEKS\"\r\nGiven second string = \"10345 good morning btechgeeks\"<\/pre>\n
The above given first string is : hello this is BTECHGEEKS\r\nThe given first string after applying capitalize() function: Hello this is btechgeeks\r\nThe above given second string is : 10345 good morning btechgeeks\r\nThe given second string after applying capitalize() function: 10345 good morning btechgeeks<\/pre>\n
Given first string = \"heLLO 1256 GOOd MOrning\"\r\nGiven second string = \"Hello btech137GEEKS\"<\/pre>\n
The above given first string is : heLLO 1256 GOOd MOrning\r\nThe given first string after applying capitalize() function: Hello 1256 good morning\r\nThe above given second string is : Hello btech137GEEKS\r\nThe given second string after applying capitalize() function: Hello btech137geeks<\/pre>\n
Program for capitalize() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the first string as static input and store it in a variable.\r\ngvn_fststr = \"hello this is BTECHGEEKS\"\r\n# Apply capitalize() function to the given first string to get the string in which\r\n# the first character is upper case and the remaining characters are lower case.\r\n# Store it in another variable.\r\ncapitize_str1 = gvn_fststr.capitalize()\r\n# Print the above given String\r\nprint(\"The above given first string is :\", gvn_fststr)\r\n# Print the above given String after applying capitalize() function.\r\nprint(\"The given first string after applying capitalize() function:\", capitize_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = \"10345 good morning btechgeeks\"\r\ncapitize_str2 = gvn_scndstr.capitalize()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying capitalize() function:\", capitize_str2)\r\n<\/pre>\n
The above given first string is : hello this is BTECHGEEKS\r\nThe given first string after applying capitalize() function: Hello this is btechgeeks\r\nThe above given second string is : 10345 good morning btechgeeks\r\nThe given second string after applying capitalize() function: 10345 good morning btechgeeks<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the first string as user input using the input() function and store it in a variable.\r\ngvn_fststr = input(\"Enter some Random String = \")\r\n# Apply capitalize() function to the given first string to get the string in which\r\n# the first character is upper case and the remaining characters are lower case.\r\n# Store it in another variable.\r\ncapitize_str1 = gvn_fststr.capitalize()\r\n# Print the above given String\r\nprint(\"The above given first string is :\", gvn_fststr)\r\n# Print the above given String after applying capitalize() function.\r\nprint(\"The given first string after applying capitalize() function:\", capitize_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = input(\"Enter some Random String = \")\r\ncapitize_str2 = gvn_scndstr.capitalize()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying capitalize() function:\", capitize_str2)\r\n<\/pre>\n
Enter some Random String = heLLO 1256 GOOd MOrning\r\nThe above given first string is : heLLO 1256 GOOd MOrning\r\nThe given first string after applying capitalize() function: Hello 1256 good morning\r\nEnter some Random String = Hello btech137GEEKS\r\nThe above given second string is : Hello btech137GEEKS\r\nThe given second string after applying capitalize() function: Hello btech137geeks<\/pre>\n
\n