get value from dictionary with default value : get « Dictionary « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » Dictionary » get 
8.10.2.get value from dictionary with default value
d2 = {'spam': 2'ham': 1'eggs': 3}         # Make a dictionary

print d2.get('spam' )                           # A key that is there
print d2.get('toast')                           # A key that is missing
print d2.get('toast', 88)
8.10.get
8.10.1.Get value by key
8.10.2.get value from dictionary with default value
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.