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

2nd Dec 2016, 2:25 AM
JoseCubes
JoseCubes - avatar
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.
2nd Dec 2016, 2:35 AM
Keto Z
Keto Z - avatar