Python 3 - dictionary str() Method


Description

The method str() produces a printable string representation of a dictionary.

Syntax

Following is the syntax for str() method −

str(dict)

Parameters

dict − This is the dictionary.

Return Value

This method returns string representation.

Example

The following example shows the usage of str() method.

#!/usr/bin/python3

dict = {'Name': 'Manni', 'Age': 7, 'Class': 'First'}
print ("Equivalent String : %s" % str (dict))

Result

When we run above program, it produces the following result −

Equivalent String : {'Name': 'Manni', 'Age': 7, 'Class': 'First'}
python_dictionary.htm
Advertisements