← Back to challenges

Count Instances of a Character in a String

PythonMediumloopsstringslanguage_fundamentalsinterview

Instructions

Create a function that takes two strings as arguments and returns the number of times the first string (the single character) is found in the second string.

Examples

char_count("a", "sample") ➞ 1

char_count("c", "Chamber of secrets") ➞ 1

char_count("b", "big fat bubble") ➞ 4

Notes

Your output must be case-sensitive (see second example).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Re-Form the Word