Python Notation?

I was just starting to use Python, and I was thinking about which notation to use. I read the PEP 8 notation guide for Python, and I agree with most things there, except for function names (which I prefer in the mixedCase style).

In C ++, I use a modified version of the Hungarian notation, in which I do not indicate the type information, but only the scope of the variable (for example, lVariable for a local variable and mVariable for a member variable of a class, g for global, s for static, for function input and output for function output.)

I don’t know if this notation style has a name, but I was wondering if I should use this notation style in Python. I am not very familiar with Python, so you guys / girls can see problems that I still cannot imagine.

I’m also interested to know what you think about it in general :) Some people may say that the code makes it less readable, but I'm used to it, and code written without these labels is code that is less readable for me.

+3
source share
6 answers

( Almost every Python programmer will say that makes the code less readable, but I'm used to it, and code written without these labels is code that is less readable for me)

FTFY.

, , Python, .

- , Python. , "mVariable", Python:

class Example(object):
    def__init__(self):
        self.my_member_var = "Hello"

    def sample(self):
        print self.my_member_var

e = Example()
e.sample()
print e.my_member_var

, - ( self.foo myinstance.foo), .

, , , " " " , , , - .

+8

PEP-8. Python.

+7

PEP8 . :

  • lowercaseCamelCase
  • _prefixedWithUnderscoreLowercaseCamelCase "private"
  • underscore_spaced ()
  • _prefixed_with_underscore_variables "private" ()
  • CapitalizedCamelCase ( )

. , , , ( ) , , , , , mumbo-jumbo ( , ).

.

  • ++ Java, CapizedCamel lowercaseCamel -.
  • , , . python name (double underscore). .
+4

.

/plug -in/library , PEP.

, - .

, , - .

, .

+2

. , , PEP-8.

, "4 1" - , . , , ( Python ).

Python . .

Java mixedCaseStuff.

C szHungarianNotation.

Python stuff_with_underscores.

You can write Java code with_python_type_function_names.
You can write Python code using javaStyleMixedCaseFunctionNamesThatAreSupposedToBeReallyExplict

while your consistency: p

+1
source

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


All Articles