<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 21, 2017 at 10:19 AM, Brett Cannon <span dir="ltr"><<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class="gmail-"><div dir="ltr">On Fri, 21 Jul 2017 at 10:08 Jason H <<a href="mailto:jhihn@gmx.com" target="_blank">jhihn@gmx.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I experimented with Python in college and I've been for close to 20 years now. (Coming and going as needed) I love the language. But there is one annoyance that I continually run into.<br>
<br>
There are basically two assignment operators, based on context, = and :<br>
a = 1<br>
{ a: 1 }<br></blockquote></span></div></div></blockquote><div><br></div><div>The `=` isn't an assignment operator, it's a *binding*. The name 'a' gets bound to the integer object "1" in your example. Don't confuse this with a language like C where it really is an assignment. If I later write:</div><div><br></div><div> a = 2</div><div><br></div><div>I haven't changed the "cell" that contains the integer object, I've rebound the NAME `a` to a different object.</div><div><br></div><div>But you've left out quite a few binding operations. I might forget some, but here are several:</div><div><br></div><div> import a # bind the name `a` to a module object</div><div> </div><div> with open(fname) as a: pass # bind the name `a` to a file handle</div><div><br></div><div> for a in [1]: pass # bind the name `a` to each of the objects in an iterable</div><div> # ... In this case, the net result is identical to `a=1`</div><div><br></div><div> def a(): pass # bind the name `a` to a function object defined in the body</div><div><br></div><div> class a: pass # bind the name `a` to a class object defined in the body</div><div> </div><div>With a bit of circuitous code, you *can* use a dictionary to bind a variable too:</div><div><br></div><div> >>> globals().update({'a':1})</div><div> >>> a</div><div> 1</div></div><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>