Skip to content
How to count in python?
Profile icon
Richard14

How can I count in python please help me

You are viewing a single comment. View All
Profile icon
WikingGaffa

You need to be more specific. What is it you want to count?
There is propably better ways to do it, but here is two examples

mylist = ["item1", "item2", "item3"] mytext = "item1 item2 item3" #count instance in text print(mytext.count("item1", 0, len(mytext))) #count instance in list counter = 0 for i in mylist: if i == "item2": counter += 1 print(counter)