Does Python have some convention for names of predicate functions? For example predicate function names end with p
for Common Lisp or ?
for Scheme. Sometimes are used prefixes like is_
or has_
, ..., but they may not be appropriate in some cases (they can be quite long to make sense and does not have to be obvious that function is predicate at first sight).
No, Python has no such official convention. Read PEP 8 for what is standardized in Python.
In Python, readability counts. If something is a predicate function, anyone should be able to immediately tell what that function is without knowing any of your standards. isinstance
, str.isupper
, hasattr
are all part of the standard library, which is a good indication of the canonical style. I can immediately tell what these functions do and return without even reading the documentation. Go with whatever you think is the most readable to someone unfamiliar with your code, which will most likely be is
or has
prefixes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With