Sunday, January 21, 2018

None on the left

A natural default, None is probably the most commonly assigned value in Python. But what happens if you move it to the left side of that equation?

In Python 2:
>>> None = 2
  File "<stdin>", line 1
SyntaxError: cannot assign to None
This is similar to what happens when you assign to a literal:
>>> 1 = 2
  File "<stdin>", line 1
SyntaxError: can't assign to literal
In Python 3 this walk on the wild side will get you a slightly different error:
>>> None = 1
  File "<stdin>", line 1
SyntaxError: can't assign to keyword
None has graduated from useful snowflake to full-blown keyword!

3 comments:

  1. Yup. Same thing with True and False, that were mere constants in Python2 and became keywords in Python3

    ReplyDelete
  2. The information you gave me about python was very important. I don't know much about it but I am looking for more information about it. I often see psychology dissertation proposal example service. Maybe if I find information about it in their blogs, I am going and see the full information of it.

    ReplyDelete
  3. What happy new year? This new year is not happy for everyone! I am looking for buy Accounting thesis service right now. I don’t know how I will write my essay and I am so screwed up. Please pray for me!

    ReplyDelete