-count() is a python function which is used to count the occurrence of element in the string or list or other data type.
- It take one argument which we want to calculate.
Example-
l=[1,2,3,4,1,1]
l.count(1) will give 3
s="programming"
s.count("p") will give 1
s.count("g") will give 2
s.count("m") will give 2
program-
print("Enter any string")
s=input()
print("Enter substring")
ss=input()
print("Original string is ",s)
print("Orginal substring is ",ss)
ans=s.count(ss,0,len(s))
print("Occurrences of substring in string is ",ans)
l=[1,2,3,4,1,1,1,1,1]
print("list is",l)
print("Occurrences of 1 in list is ",l.count(1))
Enter any string
programming
Enter substring
m
Original string is programming
Orginal substring is m
Occurrences of substring in string is 2
list is [1, 2, 3, 4, 1, 1, 1, 1, 1]
occurrences of 1 in list is 6
Enter any string
this is string of timepass
Enter substring
i
Original string is this is string of timepass
Orginal substring is i
Occurrences of substring in string is 4
list is [1, 2, 3, 4, 1, 1, 1, 1, 1]
Occurrences of 1 in list is 6