Hello.
I usually develop in ** C # **, but recently I had the opportunity to come into contact with ** Python **. After coding with the feeling of ** C # **, when I checked it again with PEP8, which is the coding convention of ** Python **, the variable declaration etc. are sober. By the way, there was a difference in the naming convention, so I roughly summarized the naming conventions for ** C # ** and ** Python **.
In PEP8, it is written that the project should give priority to the coding standard when the coding standard of the project is conflicted as follows.
Many projects have guidelines for their coding style. If it conflicts with the terms of this document, the guidelines for that project will prevail.
First, a brief explanation of the naming convention.
Naming convention | Description | Example |
---|---|---|
CamelCase | Capitalize the beginning of words except the beginning. | happyNewYear |
PascalCase | Capitalize the beginning of a word, including the beginning. | HappyNewYear |
SnakeCase | All words are lowercase. Connect with underscore. | happy_new_year |
ConstantCase | All words are capitalized. Connect with underscore. | HAPPY_NEW_YEAR |
A quick comparison list of C # and Python naming conventions.
Identifier TH> | C # TH> | Python TH> TR> |
---|---|---|
Package (namespace) TD> | PascalCase TD> | All lowercase letters TD> TR> |
HappyBirthday | happybirthday | |
Module TD> | PascalCase TD> | All lowercase / SnakeCase TD> TR> |
HappyBirthday | happybirthday / happy_birthday | |
Class TD> | PascalCase TD> | PascalCase TD> TR> |
HappyBirthday | HappyBirthday | |
Type variable TD> | PascalCase TD> | PascalCase TD> TR> |
HappyBirthday | HappyBirthday | |
Exceptions TD> | PascalCase TD> | PascalCase TD> TR> |
HappyBirthdayException | HappyBirthdayError | |
Global Variables TD> | Pascal TD> | SnakeCase TD> TR> |
HappyBirthday | happy_birthday | |
Parameters (arguments) TD> | CamelCase TD> | SnakeCase TD> TR> |
happyBirthday | happy_birthday | |
Method (function) TD> | PascalCase TD> | SnakeCase TD> TR> |
GetHappyBirthday | get_happy_birthday | |
Variables TD> | CamelCase TD> | SnakeCase TD> TR> |
happyBirthday | happy_birthday | |
Constant TD> | PascalCase TD> | ConstantCase TD> TR> |
HappyBirthday | HAPPY_BIRTHDAY |
In addition, the difference in the description such as class definition and method definition in the control statement such as indent, comment, IF etc. written in PEP8 is different. I will take the opportunity to summarize it.
reference) Python Code Style Guide (PEP8)
Recommended Posts