how to count function string in pytho code example

Example 1: count in python string

string.count(substring, start, end)
# Start and end is optional

Example 2: string count substring occurences pytohn

string.count(substring, [start_index], [end_index])

Example 3: string acharacters count in python without using len

# User inputs the string and it gets stored in variable str
str = input("Enter a string: ")

# counter variable to count the character in a string
counter = 0
for s in str:
      counter = counter+1
print("Length of the input string is:", counter)

Tags:

Misc Example