In this article, we will learn about the relevant knowledge about the python get function in the python dictionary. What does the get function mean and what role it plays will be answered in the following article.
Description
Python Dictionary (Dictionary) get() function returns the value of the specified key, or returns the default value if the value is not in the dictionary.
Syntax
get() method syntax:
dict.get(key, default=None)
Parameters
key - - The key to look up in the dictionary.
default -- If the value of the specified key does not exist, return the default value.
Return value
Returns the value of the specified key. If the value is not in the dictionary, returns the default value None.
Example Demonstration
The following example shows how to use the get() function:
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 27} print "Value : %s" % dict.get('Age') print "Value : %s" % dict.get('Sex', "Never")
The output result of the above example is:
Value : 27Value : Never
The above is all the content of this article, the built-in get function of the dictionary in python. I hope what I said and the examples I gave can be helpful to you.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of What does the python get function do? Example analysis. For more information, please follow other related articles on the PHP Chinese website!