Question -
Answer -
Description
The method str( ) produces a printable string representation of a dictionary.
Syntax
Following is the syntax for str( ) method :
str(dict)
Parameters
• diet – This is the dictionary.
Return Value
This method returns string representation.
Example :
The following examples shows the usage of str() method.
# !/user/bin/python
diet = {‘Name’ :’Zara’, ‘Age’ : 7);
print “Equivalent String : %s” %str (dict)
Let us compile and run the above program, this will produce the following result :
Equivalent String : {‘Age’ : 7, ‘Name’ : ‘Zara’}