Reputation: 6783
How would I take a string in Python like "/bin/usr/proga/file.c" and count the occurrences of the '/' character?
So, for the above example, the function would return 4.
Upvotes: 0
Views: 880
Reputation: 25599
>>> s="/bin/usr/proga/file.c"
>>> s.count("/")
4
>>> len(s.split("/"))-1
4
Upvotes: 3
Reputation: 6021
"/bin/usr/proga/file.c".count("/")
Refer to the documentation for strings.
Upvotes: 7