{"id":10286,"date":"2021-10-01T10:00:51","date_gmt":"2021-10-01T04:30:51","guid":{"rendered":"https:\/\/python-programs.com\/?p=10286"},"modified":"2021-11-22T18:33:30","modified_gmt":"2021-11-22T13:03:30","slug":"python-program-to-calculate-the-number-of-digits-and-letters-in-a-string","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-number-of-digits-and-letters-in-a-string\/","title":{"rendered":"Python Program to Calculate the Number of Digits and Letters in a String"},"content":{"rendered":"

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

\u201cString is a character collection or array\u201d<\/strong><\/p>\n

Well in Python too, for the string data type, we say the same definition. The string is a sequenced character array and is written within single, double, or three quotes. Also, Python does not have the data type character, thus it is used as a string of length 1 if we write \u2018r’.<\/p>\n

Given a string, the task is to calculate the total number of digits and letters present in the given string in Python.<\/p>\n

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

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

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

given string =Hel34lo18th3is9is38 BTech23Geeks<\/pre>\n

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

The total number of digits present in the given string [ Hel34lo18th3is9is38 BTech23Geeks ] =  10\r\nThe total number of characters present in the given string [ Hel34lo18th3is9is38 BTech23Geeks ] =  32<\/pre>\n

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

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

given string =btechgeeks2online82platform92for1000geeks<\/pre>\n

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

Enter some random string = btechgeeks2online82platform92for1000geeks\r\nThe total number of digits present in the given string [ btechgeeks2online82platform92for1000geeks ] = 9\r\nThe total number of characters present in the given string [ btechgeeks2online82platform92for1000geeks ] = 41<\/pre>\n

Program to Calculate the Number of Digits and Letters in a String<\/h2>\n

There are several ways to calculate the total number of digits and letters in the given string some of them are:<\/p>\n