0
Can somebody explain to me this:
def count_char(text, char): count = 0 for c in text: if c == char: count += 1 return count
1 Resposta
+ 6
Line by line:
# Create function
def count_char(text, char):
# Set count to 0
count = 0
# Loop through the individual characters
# in text
for c in text:
# If that character is the same as
# char (what you're looking for)...
if c == char:
# Add one to count
count += 1
# Tell us what count is
return count
All in all:
It's supposed to see how many of a given letter are in a given string.