Copyright © tutorialspoint.com

Python dictionary get() Method

previous next


Description:

This class method return a value for the given key. If key is not available then return returns default value None.

Syntax:

dict.get(key, default=None)

Parameters:

Here is the detail of parameters:

Example:

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Sex', "Never")

This produces following result:

Value : 7
Value : Never

previous next

Copyright © tutorialspoint.com