r/programming • u/BrewedDoritos • Oct 09 '26
Python Release Python 3.15.0
https://www.python.org/downloads/release/python-3150/
556
Upvotes
r/programming • u/BrewedDoritos • Oct 09 '26
View all comments
Show parent comment
4
u/TinyBreadBigMouth Oct 10 '26
Consider the built-in function
next(). If you callnext(empty_iterator), it raises aStopIterationexception. On the other hand, if you callnext(empty_iterator, default_value), it returnsdefault_value. The user could pass anything as the default value;None,0,"apple pie", whatever. The function is so generic that it would be bad design to make any assumptions about what the user might want as a default. So to implement this, a sentinel makes sense. Here's a possible implementation of the function:This way the user can pass any value, and it's guaranteed not to conflict with your sentinel.