Correct case and format of variable and methods for Python

Therefore, I know that some languages ​​were awaiting agreement.

PHP - underscore_case()[for the most part, lolo]

Java - camelCase()

FROM# - PascalCase()

and etc.

What is a python naming convention? I know this doesn't matter, but it's just interesting if there is a “best practice” method that most modules follow.

+3
source share
3 answers

Two words: PEP 8 .

PEP 8 is a (de facto) Python style guide. Some points from this document (I left some things on purpose, go to read the original document for inputs and outputs):

  • : . , .

  • . CapWords. *

  • . , .

  • : , , , . mixedCase , (, threading.py), .

  • . , , . .

  • : , . .

+7

PEP 8.

Python, Python, .

, underscore_case PascalCase .

+5

: Python Google Summer of Code

, PEP8 Google Python, .

  • "" . (_) ( import * from).
  • (__) , ( ).
  • . Java, . , .
  • CapWords , lower_with_under.py .

  • : lower_with_under
  • : lower_with_under, _lower_with_under
  • : CapWords, _CapWords
  • : CapWords
  • Functions firstLowerCapWords(),_firstLowerCapWords()
  • Global / Class constants CAPS_WITH_UNDER,_CAPS_WITH_UNDER
  • Global / class variables lower_with_under,_lower_with_under
  • Instance variables lower_with_under, _lower_with_under(protected) or __lower_with_under(indoors)
  • Method names: firstLowerCapWords(), _firstLowerCapWords()(protected) or __firstLowerCapWords()(private)
  • Function / Method Parameters: lower_with_under
  • Local variables: lower_with_under
+1
source

Source: https://habr.com/ru/post/1722827/


All Articles