দেওয়া একটি সেন্টেন্সে শব্দের সংখ্যা গণনা করার দুটি পদ্ধতি।
পদ্ধতি ১: split() ফাংশন
test_string = "Tutorials point"
res = len(test_string.split())
print("The number of words in string are:", str(res))
আউটপুট
The number of words in string are: 2
পদ্ধতি ২: strip() এবং isalpha()
import string
test_string = "Tutorials point"
res = sum([i.strip(string.punctuation).isalpha() for i in test_string.split()])
print("The number of words in string are:", str(res))
আউটপুট
The number of words in string are: 2
উপসংহার
split() দিয়ে শব্দে ভাগ করে len() নেওয়া সবচেয়ে সহজ পদ্ধতি।