[Tutor] Re: why use *get*

Luiz Siqueira Neto cybersamurai@mac.com
Fri Aug 1 14:52:01 2003


--Boundary-00=_lbrK/XJkLM6KIJs
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Thanks.  :)
--Boundary-00=_lbrK/XJkLM6KIJs
Content-Type: message/rfc822;
  name="forwarded message"
Content-Transfer-Encoding: 8bit
Content-Description: Luiz Siqueira Neto <cybersamurai@mac.com>: why use *get*

From: Luiz Siqueira Neto <cybersamurai@mac.com>
Reply-To: cybersamurai@mac.com
Organization: CyberSamurai
To: tutor@python.org
Subject: why use *get*
Date: Fri, 1 Aug 2003 10:15:06 -0300
User-Agent: KMail/1.5
MIME-Version: 1.0
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200308011015.07012.cybersamurai@mac.com>
Status: RO
X-Status: S
X-KMail-EncryptionState:  
X-KMail-SignatureState:  

I don't know why use *get*.

ex.
d = {'name':'foo'}

### all this instructions have the same result
d['name'] = d.get('name', 0) + 'bar'
d['name'] = d.get('name', 1) + 'bar'
d['name'] = d.get('name', 2) + 'bar'
d['name'] = d.get('name', 3) + 'bar'
d['name'] = += 'bar'

For what I use *x.get* ????
--Boundary-00=_lbrK/XJkLM6KIJs--