Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python dictionary get() Method


previous next AddThis Social Bookmark Button


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:

  • key: Key to be searched in the dictionary.

  • default: Value to be returned in case key does not exist.

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 Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names