In this article, you will see how to count string words in Python. You can count the number of words in a string by splitting the string into words and counting the number of words.
Step 1: Create a string
str = "Code Allow" print("str = ", str) print("str type = ", type(str))
Step 2: Count string words
print("Words = ", len(str.split()))
str = Code Allow str type = <class 'str'> Words = 2
Free resources to learn advanced skills: AiHints and CodeAllow