Python - Convert Dictionary Object into String Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 3 Likes 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. Create Quiz Comment G garg_ak0109 Follow 3 Improve G garg_ak0109 Follow 3 Improve Article Tags : Python python-dict Python dictionary-programs Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like