count(): Number of presence of a string

my_str="Welcome to"
print(my_str.count('co'))      # Output is 2
print(my_str.count('co',4))    # Output is 1 
print(my_str.count('co',4,18)) # Output is 0
print(my_str.count('o',4,9))   # Output is 1
print(my_str.count('o',4,10))  # Output is 2
Note : In last line in above code the char o is at 4th and 94th position.
search_string : String to be searched for matching inside main string.
start: Optional , search can be started from this position
end : Optional , search can be ended just before this position. Using a list
print(my_list.count('two'))      # Output is 1
All String methods

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer