18.11.2014 Views

Zelle - Chapter 11.pdf - CTools

Zelle - Chapter 11.pdf - CTools

Zelle - Chapter 11.pdf - CTools

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

What get() effectively does...<br />

• The get() method basically<br />

does an implicit if checking<br />

to see if the key exists in the<br />

dictionary and if the key is<br />

not there - return the<br />

default value<br />

• The main purpose of get() is<br />

to save typing this four line<br />

pattern over and over<br />

d = dict()<br />

x = d.get(“fred”,0)<br />

d = dict()<br />

if “fred” in d:<br />

x = d[“fred”]<br />

else:<br />

x = 0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!