Great Idea, I have joined the mailing list to write the same idea.

As I can't find the great difference between Final and Constant, So, I will use 
 the name Final.

I suggest one the following syntax:

from collection import Final

》x = Final(100)

》print(x)
》100

》y = x*2
》Print(Y)
》200
》print (type(x))
》< Final object.int at xxxxx>
》x=0
  File "<stdin>", line 1
SyntaxError: can't assign to Final

My understanding is Final will prevent x from reassigned.
But if x is dict or list or string. it can be mutated in place.
》x = Final([1,2])
》x.append(3)
》print(x)
[1,2,3]

If the programmer needs list that can't changed, he should move to other data 
structure like tuple. By using tuple & Final,  the x will not accept 
reassigning nor mutation.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QITITJL55FZLAGO7LYNIOMSEWTKF3ZV6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to