Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

I can't think of a single case where using sentinel values is necessary or appropriate in Python.

Generally speaking, one should just return from within the loop.



I get what you're saying, but even when sentinels are used inside a function, returning a -1 to the caller seems like a pretty bad API. It's OK to raise ValueError! I had thought the idiomatic sentinel value was an instance of object() you could is against, anyway.


I agree - especially when you're returning a list index, since `[-1]` is a valid index in Python.


Funky OS of FFI APIs... but Python has a nice way of abstracting away the pattern using the second argument to iter().




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: