jakevdp / WhirlwindTourOfPython

The Jupyter Notebooks behind my OReilly report, "A Whirlwind Tour of Python"
Creative Commons Zero v1.0 Universal
3.73k stars 1.61k forks source link

Fix typo in 03-Semantics-Variables.ipynb #5

Closed cdeil closed 7 years ago

cdeil commented 7 years ago

@jakevdp - First of all - thank you for writing and sharing these notebooks! We'll be teaching a Python bootcamp to astronomers in 2 weeks and plan to use your materials.

This PR fixes a typo in the 03-Semantics-Variables.ipynb notebook at the very end of this section: http://nbviewer.jupyter.org/github/jakevdp/WhirlwindTourOfPython/blob/master/03-Semantics-Variables.ipynb#Python-Variables-Are-Pointers


The current sentence is:

When we call x += 5, we are not modifying the value of the 5 object pointed to by x, but rather we are changing the object to which x points. For this reason, the value of y is not affected by the operation.

I wonder if this could be made clearer by adding in "new int object with value 15", i.e. something like

When we call x += 5, we are not modifying the value of the 10 object pointed to by x, but rather we are creating a new integer object with value 15, and change the x variable to point to that new object. For this reason, the value of y is not affected by the operation.

I didn't make the change here, because I wasn't sure it's better, so I just fixed the typo.

jakevdp commented 7 years ago

Thanks for catching the typo – I'll merge this. I do like your suggested modification, so I'll make that change separately. Thanks!

jakevdp commented 7 years ago

Small detail on your change: this operation does not create a new value 15, but points it to an already existing 15 singleton. I'll try to figure out how to say that correctly without having to digress into the details of how Python optimizes handling of integer objects in memory!

cdeil commented 7 years ago

Yes, right, I forgot: CPython pre-creates small ints. Probably not something to explain to people at that point in their Python career.

That's why I didn't attempt to write a better version ... :-)

jakevdp commented 7 years ago

I just pushed the change here: https://github.com/jakevdp/WhirlwindTourOfPython/commit/0269219cb4035463e1d66236013e25ef1d098d14

jakevdp commented 7 years ago

The ambiguity in the word "new" there (globally new or new in relation to x?) covers all the bases :smile:

cdeil commented 7 years ago

👍 to 0269219cb4035463e1d66236013e25ef1d098d14 Short and correct now.

Just FYI, in case you hadn't seen it: one other intro I looked at yesterday was http://nbviewer.jupyter.org/github/oreillymedia/python_epiphanies/blob/master/Python-Epiphanies-All.ipynb#2-Names and there it's explained in more detail what happens. I guess going in depth in your whirlwind tour isn't appropriate, but specifically at this one point about how Python works, that other O'Reilly course / free notebook might be worth pointing out.

jakevdp commented 7 years ago

That's a nice discussion! I think that's based on Stuart Williams' PyCon tutorials by the same name, so I'm not surprised it's very good :smile: It's a bit more detail than I'd want to go into here though.