Python Forum
Searching for parts of a string or word
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching for parts of a string or word
#8
There is also str.count method:

>>> help(str.count)
Help on method_descriptor:

count(...)
    S.count(sub[, start[, end]]) -> int

    Return the number of non-overlapping occurrences of substring sub in
    string S[start:end].  Optional arguments start and end are
    interpreted as in slice notation.

>>> 'abrakadabra'.count('abra')
2
>>> 'abrakadabra'.count('some')
0
Ulumulu likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Searching for parts of a string or word - by perfringo - Mar-15-2021, 04:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation A function that takes a word and a string of forbidden letters pooyan89 5 4,838 Jun-12-2019, 09:44 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020