Python - Convert Dictionary Object into String Last Updated : 11 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In Python, there are situations where we need to convert a dictionary into a string format. For example, given the dictionary {'a' : 1, 'b' : 2} the objective is to convert it into a string like "{'a' : 1, 'b' : 2}". Let's discuss different methods to achieve this:Using strThe simplest way to convert a dictionary to a string is by using the built-in function "str()" for string conversion. Python a = {'a': 1, 'b': 2} b = str(a) print(b, type(b)) Output{'a': 1, 'b': 2} <class 'str'> Explanation: str() function converts the dictionary into its string representation.Using json.dumpsAnother method is to use the dumps function from the json module for converting a dictionary into a JSON-formatted string. Python import json a = {'a': 1, 'b': 2} b = json.dumps(a) print(b) Output{"a": 1, "b": 2} Explanation:json.dumps converts the dictionary to a string following JSON format, useful when working with APIs or web applications.It adds double quotes around keys and values if they are string values for JSON formatting.Using reprThis method uses repr() function and converts the dictionary into a string representation that can be evaluated back into a dictionary. Python a = {'a': 1, 'b': 2} b = repr(a) print(b) Output{'a': 1, 'b': 2} Explanation:repr() function produces a detailed string representation of the dictionary similar to str.Useful when we need the output as a valid Python expression.Using String ConcatenationThis method manually constructs the string representation of the dictionary by concatenating its key-value pairs. Python a = {'a': 1, 'b': 2} b = "{" + ", ".join(f"'{k}': {v}" for k, v in a.items()) + "}" print(b) Output{'a': 1, 'b': 2} Explanation:join() function Joins key-value pairs as strings to create a custom output format.This method offers flexibility in creating custom formats but is less efficient than built-in functions. Comment More infoAdvertise with us Next Article Python - Convert Dictionary Object into String G garg_ak0109 Follow Improve Article Tags : Python python-dict Python dictionary-programs Practice Tags : pythonpython-dict Similar Reads Convert nested Python dictionary to object Let us see how to convert a given nested dictionary into an object Method 1 : Using the json module. We can solve this particular problem by importing the json module and use a custom object hook in the json.loads() method. python3 # importing the module import json # declaringa a class class obj: # 2 min read Python - Converting list string to dictionary Converting a list string to a dictionary in Python involves mapping elements from the list to key-value pairs. A common approach is pairing consecutive elements, where one element becomes the key and the next becomes the value. This results in a dictionary where each pair is represented as a key-val 3 min read Convert JSON to dictionary in Python JSON stands for JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the Python JSON package into Pytho 4 min read Convert Object to String in Python Python provides built-in type conversion functions to easily transform one data type into another. This article explores the process of converting objects into strings which is a basic aspect of Python programming.Since every element in Python is an object, we can use the built-in str() and repr() m 2 min read Convert Unicode String to Dictionary in Python Python's versatility shines in its ability to handle diverse data types, with Unicode strings playing a crucial role in managing text data spanning multiple languages and scripts. When faced with a Unicode string and the need to organize it for effective data manipulation, the common task is convert 2 min read Like