Write a Python Program to Count Number of Words and Characters in given String

Write a python program to count number of words and characters in a given string. is provided on this page.

Write A Python Program To Count Number Of Words And Characters In A Given String.

Program 1


def word_and_character_count(string):
    character_count = len(string)
    print("Character count : ", character_count)
    words = string.split()
    print("Word count : ", len(words))
    

word_and_character_count('This sentence has 8 words and 44 characters.')

Output

Character count :  44
Word count :  8

Related To Python

Comments