str()

Consider a situation where you want to convert a dictionary into a string; here you can use the str() function. The syntax of the method is as follows:

str(dict) 

Consider the following example:

>>> port = {80: "http", 443: "https", 23:"telnet"}
>>> port
{80: 'http', 443: 'https', 23: 'telnet'}
>>> str(port)
"{80: 'http', 443: 'https', 23: 'telnet'}"
>>>

You can easily see the double quotes around the dictionary. Let's get the max key from the dictionary, using the max() function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.188.238