Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use "camel case" or underscores in Python? [duplicate]

So which is better and why?

def my_function(): 

or

def myFunction(): 
like image 428
tdc Avatar asked Jan 18 '12 10:01

tdc


People also ask

Is camel case better than underscore?

Results indicate that camel casing leads to higher accuracy among all subjects regardless of training, and those trained in camel casing are able to recognize identifiers in the camel case style faster than identifiers in the underscore style.

Why does Python use underscores instead of Camelcase?

1 Answer. PEP8 is Pythons official style guide and it recommends : Function names should be lowercase, with words separated by underscores as necessary to improve readability.

When should we use camel case?

When multiple words are used to form a variable, camel case joins those words together, without any white space, and delineates the start of each new word with a capital letter. In contrast, snake case uses an underscore between words to create separation.


2 Answers

for everything related to Python's style guide: i'd recommend you read PEP8.

To answer your question:

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

like image 166
aayoubi Avatar answered Sep 21 '22 15:09

aayoubi


PEP 8 advises the first form for readability. You can find it here.

Function names should be lowercase, with words separated by underscores as necessary to improve readability.

like image 45
David M Avatar answered Sep 23 '22 15:09

David M