Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python predicate function name convention

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).

like image 910
user3752871 Avatar asked Aug 10 '15 17:08

user3752871


1 Answers

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.

like image 127
Alyssa Haroldsen Avatar answered Oct 12 '22 23:10

Alyssa Haroldsen