count()

All String methods
my_str.count(search_string,start,end))
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.
my_str="Welcome to plus2net.com"
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.

Using a list
my_list=['one','two','three']
print(my_list.count('two'))      # Output is 1


All String methods

Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    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-2022 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer