How to Print Dictionary Keys in Python Last Updated : 26 Apr, 2025 Comments Improve Suggest changes Like Article Like Report We are given a dictionary and our task is to print its keys, this can be helpful when we want to access or display only the key part of each key-value pair. For example, if we have a dictionary like this: {'gfg': 1, 'is': 2, 'best': 3} then the output will be ['gfg', 'is', 'best']. Below, are the methods of How to Print Dictionary Keys in Python.Using keys() MethodIterating Through DictionaryUsing List ComprehensionUsing keys() MethodThis method uses the keys() function to get a view object of the dictionary’s keys and then converts it into a list. Python d = {'name': 'John', 'age': 25, 'city': 'New York'} a = list(d.keys()) print(a) Output['name', 'age', 'city'] Explanation: The keys() method returns a view object that displays a list of all the keys in the dictionary. Using list() converts the view object into a list, which is then printedIterating Through DictionaryWe can iterate through the dictionary directly using a for loop and print each key individually. This method is straightforward and concise, making it a popular choice for printing dictionary keys. Python d = {'name': 'John', 'age': 25, 'city': 'New York'} for key in d: print(key) Outputname age city Explanation: This method directly iterates over the dictionary. By default, the for loop iterates through the dictionary’s keys, printing each key in the iteration.Using List ComprehensionList comprehension is used here to create a list of dictionary keys in a single, compact expression. Python d = {'name': 'John', 'age': 25, 'city': 'New York'} a = [key for key in d] print(a) Output['name', 'age', 'city'] Explanation: List comprehension creates a new list by iterating over the dictionary and collecting its keys. This method is more compact and functional in nature. The resulting list is then printed. Comment More infoAdvertise with us Next Article How to Print Dictionary Keys in Python reshmah Follow Improve Article Tags : Python Python Programs python-dict Practice Tags : pythonpython-dict Similar Reads How to Print a Dictionary in Python Python Dictionaries are the form of data structures that allow us to store and retrieve the key-value pairs properly. While working with dictionaries, it is important to print the contents of the dictionary for analysis or debugging.Example: Using print FunctionPython# input dictionary input_dict = 3 min read How to Initialize Dictionary in Python In Python dictionary, each key is unique and we can store different data types as values. The simplest and most efficient method to initialize a dictionary is using curly braces {}. This is the easiest and most common way to create a dictionary. We can use curly braces '{} ' and separate the keys an 2 min read Get Total Keys in Dictionary - Python We are given a dictionary and our task is to count the total number of keys in it. For example, consider the dictionary: data = {"a": 1, "b": 2, "c": 3, "d": 4} then the output will be 4 as the total number of keys in this dictionary is 4.Using len() with dictThe simplest way to count the total numb 2 min read Dictionary keys as a list in Python In Python, we will encounter some situations where we need to extract the keys from a dictionary as a list. In this article, we will explore various easy and efficient methods to achieve this.Using list() The simplest and most efficient way to convert dictionary keys to lists is by using a built-in 2 min read Python - How to Iterate over nested dictionary ? In this article, we will discuss how to iterate over a nested dictionary in Python. Nested dictionary means dictionary inside a dictionary and we are going to see every possible way of iterating over such a data structure. Nested dictionary in use: {'Student 1': {'Name': 'Bobby', 'Id': 1, 'Age': 20} 3 min read Python Print Dictionary Keys and Values When working with dictionaries, it's essential to be able to print their keys and values for better understanding and debugging. In this article, we'll explore different methods to Print Dictionary Keys and Values.Example: Using print() MethodPythonmy_dict = {'a': 1, 'b': 2, 'c': 3} print("Keys:", l 2 min read Key Index in Dictionary - Python We are given a dictionary and a specific key, our task is to find the index of this key when the dictionaryâs keys are considered in order. For example, in {'a': 10, 'b': 20, 'c': 30}, the index of 'b' is 1.Using dictionary comprehension and get()This method builds a dictionary using dictionary comp 2 min read Add a key value pair to Dictionary in Python The task of adding a key-value pair to a dictionary in Python involves inserting new pairs or updating existing ones. This operation allows us to expand the dictionary by adding new entries or modify the value of an existing key.For example, starting with dictionary d = {'key1': 'geeks', 'key2': 'fo 3 min read Remove Kth Key from Dictionary - Python We are given a dictionary we need to remove Kth key from the dictionary. For example, we are given a dictionary d = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3', 'key4': 'value4'} we need to remove the key2 so that the output should be {'key1': 'value1', 'key3': 'value3', 'key4': 'value4'}. 3 min read Python - Print dictionary of list values In this article, we will explore various ways on How to Print Dictionary in Python of list values. A dictionary of list values means a dictionary contains values as a list of dictionaries in Python. Example: {'key1': [{'key1': value,......,'key n': value}........{'key1': value,......,'key n': value} 4 min read Like