1

Python built-in functions don't follow camelcase

"abc".startswith("a")
"abc".endswith("a")
random.randint(1,3)

Should I use camelcase or underscore or all small chars like python built-in functions? or are there any good design conventions to name functions, variables?

Ankush
  • 675
  • 2
  • 13
  • 29
  • Python is moving the built-in functions from camelCase, which is hard to read, to underscores. – Pedro Lobito Mar 26 '17 at 19:42
  • Possible duplicate of [What is the naming convention in Python for variable and function names?](https://stackoverflow.com/questions/159720/what-is-the-naming-convention-in-python-for-variable-and-function-names) – jcarder Mar 26 '17 at 19:44
  • 1
    Many parts of the Python standard library predate PEP8. They should not necessarily be seen as examples. – Martijn Pieters Mar 26 '17 at 19:45

1 Answers1

4

Have a look at PEP 8 -- Style Guide for Python Code.

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

mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility.

Ohjeah
  • 1,269
  • 18
  • 24
  • 3
    I don't see the benefit of following PEP 8, while Javascript, php, swift and other languages mostly use camelCase for method. You shouldn't change your coding style for each language, that's stupid. In general, camelCase is the better choice https://whathecode.wordpress.com/2011/02/10/camelcase-vs-underscores-scientific-showdown/ – TomSawyer Sep 14 '17 at 18:17
  • 1
    @TomSawyer _"In general, camelCase is the better choice ..."_ I pretty much argue the opposite in that article. :) But yeah, some (mostly those not reading to the end) interpret the results as favoring camelCase. – Steven Jeuris Apr 04 '19 at 09:02