Python's pre-declared constants are kinda weird
rbanffy
167 points
163 comments
August 25, 2026
Related Discussions
Found 5 related stories in 61.3ms across 4,390 title embeddings via pgvector HNSW
- Thinking in Python pjacotg · 124 pts · August 22, 2026 · 45% similar
- Python Polars Cheatsheet (based on our O'Reilly book) jeroenjanssens · 169 pts · August 18, 2026 · 38% similar
- When str.lower() is a security vulnerability in Python – Seth Larson rbanffy · 92 pts · August 25, 2026 · 36% similar
- Self-contained highly-portable Python distributions jcbhmr · 129 pts · July 27, 2026 · 35% similar
- Some more things about Django I've been enjoying ibobev · 11 pts · July 22, 2026 · 35% similar
Discussion Highlights (18 comments)
xg15
Isn't "..." then also behaving like True, False and None, i.e. being a lexical token that rewolves to a hardwired value during parsing?
zahlman
Past: https://news.ycombinator.com/item?id=49284392 (with my comment), https://news.ycombinator.com/item?id=49250370 . Nice to see it get attention this time.
echelon
I used to like Python in the 2010s when it felt like a breath of fresh air relative to PHP and Perl. Now it feels like a weird PHP itself that is slow, brittle, and dangerous to write code at scale in. The loose typing, potluck standard library, and horrible package manager (insofar as the community does not know how to package code) all feel so dated.
nneonneo
The __debug__ constant is really weird - any block of code guarded with `if __debug__:` will be entirely omitted from the bytecode under PYTHONOPTIMIZE=1. This and `assert` are the only two examples of real “conditional compilation” in Python. This is also the reason why you cannot assign to __debug__: doing so would make it possible to invalidate the compiler’s assumption about `if __debug__:` statements.
jMyles
I made a constant library for python which I liked some years ago. I wonder if any of my ideas made it in: https://github.com/nucypher/constantSorrow/blob/master/tests...
neillyons
I remember reading that in early versions of Python there was no built in True and False. Each user would implement this themselves as True = 1 False = 0 then later these got added to the language. In Python 2 you could still reassign and swap them so that 'if False' was actually true! True, False = False, True Python 3 you could no longer reassign them.
Lucasoato
Wow, I wish to understand the internal details of Python implementation that makes it behave in such a way :)
moomoo11
just my 2c but py is honestly one of the worst languages and ecosystems i’ve used in my life. for all the hate js used to get, py is at least a few magnitudes worse. my opinion ofc. don’t get mad xD
snitty
Python is three scripting languages in a trench-coat.
hmokiguess
Python is awful. There are so many one offs in libraries, none agree on a style, it’s slow, and it’s way too easy to do the wrong thing. I often work with data scientists and have to productionize their jupyter notebooks which is pure suboptimal hell. I guess it must be a good easy learning curve for research/scratchpad
Revanche1367
A lot of Python design decisions have felt weird and off to me but they’ve long justified it by saying that it’s those little ugly design choices that make the language so usable and effective in practice compared to more well-designed languages that hardly anybody uses. I’m not enough of an expert to clearly say if that’s really true, but imo, there’s a repeated pattern of slightly weirdly designed languages becoming super popular: Python, Javascript, perhaps C as well. Or, maybe we only notice the weirdness because these languages are used so much and get nitpicked to no end.
jherskovic
Python has some absolutely kick-ass libraries, even without C. It has Django, for those of us who like developing web apps but never could fall in love with Ruby on Rails. And Django is amazing. I've also yet to see a better language for writing quick ETL scripts and pipelines. Also, an 'I need a script for $SYSADMIN_TASK but I want to be able to read it later.' Anything dominated by external latencies (web, databases, etc) will be fast enough for many uses in Python. Sure, it's not a language to write a web browser or game engine in. And it is slow. But it has some very strong niches outside of ML/Data science. Personally, I love it. To each their own.
numpad0
> True, False, and None are keywords. they aren't identifiers, they're just straight up their own lexical tokens. Could this be so that the interpreter don't inadvertently manipulate them or pass them to a function? param=None and param="" can be very different.
persedes
Love the investigation and write up. Took me down some rabbit holes, but interesting to see the chatter about the fix here: https://github.com/python/cpython/issues/80233 Initially you could reassign True,False but that was verboten with the switch to python 3! The walrus operator was the one simply an oversight. https://python-history.blogspot.com/2013/11/story-of-none-tr... Explanation from Guido himself
throwaway314155
Queue the hoards of Python haters apparently.
YuechenLi
Python is just such a weird language in general despite its popularity that I honestly cannot recommend anyone who starts programming to choose Python as their first language, contrary to popular sentiments. I mean, I was one of the first person to start using Python when I was in grad school almost a decade ago when everybody else in my field was still using Matlab for their lab code, for the simply reason that Numpy was less awful than Matlab and I needed something that can easily print graphs to PDFs. The only thing good I can say about Python nowadays is that it's easy to get started for the first five minutes, and then you'll have to deal with all of its weirdness: significant whitespace, truthiness, duck typing, GIL, distribution/packaging, etc, etc. I was a big fan of Julia as the potential replacement for Python for science for such a long time and I had evangelized it a lot previously, but recently I've been more and more convinced that JIT/multiple dispatch was only good if you already know how to program well to begin with, which for a lot of academics who are not working in computer science, they write quite horrific code. I think it may be better off to skip Python altogether and write your code in a statically typed language to begin with.
gucci-on-fleek
If you count pre-release versions, there are actually 7 pre-declared constants, since Python 3.15 (planned for release in November [0]) adds a new constant "TYPE_CHECKING" that should behave like "Ellipsis" and "NotImplemented" do right now [1]. [0]: https://peps.python.org/pep-0790/#schedule [1]: https://peps.python.org/pep-0781/#backwards-compatibility
luciana1u
you could shadow True for twenty years and Python just shrugged, then one day it's a SyntaxError and every tutorial you ever wrote breaks. peak Python, honestly.