{"id":10217,"date":"2021-09-30T12:00:56","date_gmt":"2021-09-30T06:30:56","guid":{"rendered":"https:\/\/python-programs.com\/?p=10217"},"modified":"2021-11-22T18:34:39","modified_gmt":"2021-11-22T13:04:39","slug":"python-program-to-calculate-the-number-of-words-and-the-number-of-characters-present-in-a-string","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-number-of-words-and-the-number-of-characters-present-in-a-string\/","title":{"rendered":"Python Program to Calculate the Number of Words and the Number of Characters Present in a String"},"content":{"rendered":"

Strings in Python:<\/strong><\/p>\n

In Python, a string\u00a0may be a\u00a0<\/span>sequence of characters. It is\u00a0an information<\/span>\u00a0type that has been derived. Strings are unchangeable. This means\u00a0that when\u00a0<\/span>they have been\u00a0<\/span>defined,\u00a0they can not\u00a0<\/span>be modified. Many Python functions change strings,\u00a0like\u00a0<\/span>replace(), join(), and split(). They do not, however, alter the original string. They make\u00a0a duplicate<\/span>\u00a0of a string, alter it, then return it to the caller.<\/p>\n

Given a string, the task is to count the words and the total number of characters in the given string in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string ='Hello this is btechgeeks'<\/pre>\n

Output:<\/strong><\/p>\n

Total characters present in given string { Hello this is btechgeeks } = 24\r\nTotal words present in given string { Hello this is btechgeeks } = 4<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string ='hello this is btechgeeks online platform for coding students'<\/pre>\n

Output:<\/strong><\/p>\n

Total characters present in given string { hello this is btechgeeks online platform for coding students } = 61\r\nTotal words present in given string { hello this is btechgeeks online platform for coding students } = 9<\/pre>\n

Program to Calculate the Number of Words and the Number of Characters Present in a String<\/h2>\n

There are several ways to count the total number of words and characters in the given string in python some of them are:<\/p>\n