Find Frequency of Characters in Python Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will explore various methods to count the frequency of characters in a given string. One simple method to count frequency of each character is by using a dictionary.Using DictionaryThe idea is to traverse through each character in the string and keep a count of how many times it appears. Python s = "GeeksforGeeks" freq = {} for c in s: if c in freq: freq[c] += 1 else: freq[c] = 1 print(freq) Output{'G': 2, 'e': 4, 'k': 2, 's': 2, 'f': 1, 'o': 1, 'r': 1} Explanation: We use a dictionary freq to store each character as the key and its count as the value. We loop through the string s and check if the character is already in the dictionary. If it is then increase its count by 1. Otherwise, set its frequency to 1.Let's explore other various methods to find the frequency of each character in String:Table of ContentUsing Counter from collections LibraryUsing a Dictionary ComprehensionUsing Counter from collections LibraryThe collections module has a built-in Counter class to count character frequencies in a string. Python from collections import Counter s = "GeeksforGeeks" # Count character frequency using Counter freq = Counter(s) print(dict(freq)) Output{'G': 2, 'e': 4, 'k': 2, 's': 2, 'f': 1, 'o': 1, 'r': 1} Explanation: Counter(s) counts the frequency of each character in s and returns a Counter object which is a dictionary-like collection. To convert back to dictionary we can wrap the freq with dict()Using Dictionary ComprehensionA dictionary comprehension can also be used to count character frequencies in a concise form. Python s = "GeeksforGeeks" # Count characters using dictionary comprehension freq = {c: s.count(c) for c in s} print(freq) Output{'G': 2, 'e': 4, 'k': 2, 's': 2, 'f': 1, 'o': 1, 'r': 1} Explanation: {char: s.count(char) for char in s} creates a dictionary where each character in s is a key and s.count(c) gives its frequency. Comment More infoAdvertise with us Next Article Count Occurrences of a Character in String in Python M manjeet_04 Follow Improve Article Tags : Python python-string Python string-programs Practice Tags : python Similar Reads Python | Character Encoding Finding the text which is having nonstandard character encoding is a very common step to perform in text processing. All the text would have been from utf-8 or ASCII encoding ideally but this might not be the case always. So, in such cases when the encoding is not known, such non-encoded text has to 2 min read Find all duplicate characters in string in Python In this article, we will explore various methods to find all duplicate characters in string. The simplest approach is by using a loop with dictionary.Using Loop with DictionaryWe can use a for loop to find duplicate characters efficiently. First we count the occurrences of each character by iteratin 2 min read Ways to increment a character in Python In python there is no implicit concept of data types, though explicit conversion of data types is possible, but it not easy for us to instruct operator to work in a way and understand the data type of operand and manipulate according to that. For e.g Adding 1 to a character, if we require to increme 4 min read Count Occurrences of a Character in String in Python We are given a string, and our task is to count how many times a specific character appears in it using Python. This can be done using methods like .count(), loops, or collections.Counter. For example, in the string "banana", using "banana".count('a') will return 3 since the letter 'a' appears three 2 min read Count Occurrences of a Character in String in Python We are given a string, and our task is to count how many times a specific character appears in it using Python. This can be done using methods like .count(), loops, or collections.Counter. For example, in the string "banana", using "banana".count('a') will return 3 since the letter 'a' appears three 2 min read chr() Function in Python chr() function returns a string representing a character whose Unicode code point is the integer specified. chr() Example: Python3 num = 97 print("ASCII Value of 97 is: ", chr(num)) OutputASCII Value of 97 is: a Python chr() Function Syntaxchr(num) Parametersnum: an Unicode code integerRet 3 min read Like