Python dictionary method str() supplies a printable string symbol of a dictionary. The string unit comprises a number of helpful steady and groups, as well as a few denounced legacy purposes that are also obtainable as techniques on strings. In addition, Python’s constructed string classes reinforce the sequence kind methods explained in the Sequence Types — str, buffer, xrange section, Unicode, bytearray, list, and Tuple also the string-specific methods portrayed in the String Methods section. To output, arrangement strings utilize template strings or the % operator defined in the String Formatting Operations part. Also, see the str module for cord functions rooted in regular expressions.
Following is the syntax for str() method:
str(dict)
This method returns string representation.
The following example shows the usage of str() method.
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7}; print "Equivalent String : %s" % str (dict)
When we run the above program, it produces the following result:
Equivalent String : {'Age': 7, 'Name': 'Zara'}
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.