Python function naming convention

by dabadaba   Last Updated September 08, 2017 10:05 AM

It is not a deal breaker but I would like to know what is the convention when naming methods, especially the case of getters.

Point 1: should the word get be preset in the name or not? i.e. person.get_name() or simply person.name().

Should underscores be used or not? Usually I use underscores to separate words: person.get_name() but often I see this format: person.getname(), for example sys.getsizeof(object).

Lastly, should I refer to the argument(s) in the function name? Or rather, when should I refer to the arguments? For example, salary_manager.calculate_salary(worker) or salary_manager.calculate_salary_for(worker)? Using the same example than before we find that sys.getsizeof(object) does refer to the argument with the preposition of, the other alternative would be omitting it: sys.getsize(object).



Related Questions


Python file naming convention?

Updated October 27, 2017 22:05 PM

How to name variables that clash with functions?

Updated August 21, 2016 08:03 AM

Method naming: to vs as vs get

Updated April 25, 2018 02:05 AM