3
How do I read two strings and check the number of occurrences of the second string in the first?
Example: If the first string typed is "abracadabra"
and the second "bra"
, then the number of occurrences will be 2.
3
How do I read two strings and check the number of occurrences of the second string in the first?
Example: If the first string typed is "abracadabra"
and the second "bra"
, then the number of occurrences will be 2.
7
Use str.Count:
>>> nStr = 'abracadabra'
>>> nStr.count('bra')
Font - Determining how Many times a substring occurs in a string in Python
0
frase = str(input("Digite a frase a se analisada: "))
palavra = str(input("Ocorrências da palavra/letra: "))
resultado = frase.count(palavra)
print(f"Na frase |{frase}|, a palavra/letra |{palavra}| apareceu {resultado} vezes")
Browser other questions tagged python string
You are not signed in. Login or sign up in order to post.