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

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

Writing readable code and not overdoing it with naming

Updated December 05, 2017 13:05 PM

Why do software use Win32 name?

Updated August 29, 2017 12:05 PM