{"id":24538,"date":"2021-10-22T09:59:19","date_gmt":"2021-10-22T04:29:19","guid":{"rendered":"https:\/\/python-programs.com\/?p=24538"},"modified":"2021-11-05T19:05:55","modified_gmt":"2021-11-05T13:35:55","slug":"python-string-title-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-title-function-with-examples\/","title":{"rendered":"Python String title() Function with Examples"},"content":{"rendered":"
In the previous article, we have discussed Python String split() Method Examples<\/a> The title() method returns a string in which the first character of each word is capitalized. As in a header or a title.<\/p>\n If the word contains a number or a symbol, the following letter will be converted to upper case.<\/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 Note:<\/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 Are you facing difficulties in finding all the methods that a string object can call in python? Have a glance at this Python String Method Examples<\/a> Tutorial & meet such challenges with ease.<\/p>\n In the previous article, we have discussed Python String split() Method Examples Python String title() Function: The title() method returns a string in which the first character of each word is capitalized. As in a header or a title. If the word contains a number or a symbol, the following letter will be converted to …<\/p>\n
\nPython String title() Function:<\/strong><\/p>\nstring.title()<\/pre>\n
Given first string = \"hello this is btechgeeks\"\r\nGiven second string = \"10345 good morning 2a2a btechgeeks\"<\/pre>\n
The above given first string is : hello this is btechgeeks\r\nThe given first string after applying title() function:\r\nHello This Is Btechgeeks\r\nThe above given second string is : 10345 good morning 2a2a btechgeeks\r\nThe given second string after applying title() function:\r\n10345 Good Morning 2A2A Btechgeeks<\/pre>\n
It is worth noting that the first letter after a non-alphabet \r\nletter is converted to an upper case letter.<\/pre>\n
Given first string = \"welcome to Python-Programs\"\r\nGiven second string = \"HELLO ALL GOOD MORNING\"<\/pre>\n
The above given first string is : welcome to Python-Programs\r\nThe given first string after applying title() function:\r\nWelcome To Python-Programs\r\nThe above given second string is : HELLO ALL GOOD MORNING\r\nThe given second string after applying title() function:\r\nHello All Good Morning<\/pre>\n
Program for String title() 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 title() function to the given first string that returns a string in\r\n# which the first character of each word is capitalized. As in a header or a title.\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.title()\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 title() function.\r\nprint(\"The given first string after applying title() function:\")\r\nprint(rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = \"10345 good morning 2a2a btechgeeks\"\r\nrslt_str2 = gvn_scndstr.title()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying title() function:\")\r\nprint(rslt_str2)\r\n<\/pre>\n
The above given first string is : hello this is btechgeeks\r\nThe given first string after applying title() function:\r\nHello This Is Btechgeeks\r\nThe above given second string is : 10345 good morning 2a2a btechgeeks\r\nThe given second string after applying title() function:\r\n10345 Good Morning 2A2A 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 title() function to the given first string that returns a string in\r\n# which the first character of each word is capitalized. As in a header or a title.\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.title()\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 title() function.\r\nprint(\"The given first string after applying title() function:\")\r\nprint(rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = input(\"Enter some Random String = \")\r\nrslt_str2 = gvn_scndstr.title()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying title() function:\")\r\nprint(rslt_str2)\r\n<\/pre>\n
Enter some Random String = welcome to Python-Programs\r\nThe above given first string is : welcome to Python-Programs\r\nThe given first string after applying title() function:\r\nWelcome To Python-Programs\r\nEnter some Random String = HELLO ALL GOOD MORNING\r\nThe above given second string is : HELLO ALL GOOD MORNING\r\nThe given second string after applying title() function:\r\nHello All Good Morning<\/pre>\n
\n