Python dictionary str() Method


Contents

Description

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.

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/python

dict = {'Name': 'Zara', 'Age': 7};
print "Equivalent String : %s" % str (dict)

When we run above program, it produces 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.



Navigation
Tutorial
Tutorial
Tutorial