Can "None" be Reassigned in Python?

Starting with Python 2.4+, None cannot be reassigned:

# Python 2.4+
# SyntaxError: cannot assign to None
None = 'foo'

This guarantees that:

  • It is truly a constant, and;
  • All None references are always the same.

Please note that in versions of Python prior to 2.4, it is possible to reassign None.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.