python count characters in list code example Example: count characters in string python >>> sentence = 'Mary had a little lamb' >>> sentence.count('a') 4