Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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.
"/bin/usr/proga/file.c".count("/")
Refer to the documentation for strings.
Add a comment
>>> s="/bin/usr/proga/file.c" >>> s.count("/") 4 >>> len(s.split("/"))-1 4
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.