[Introduction to Python] I compared the naming conventions of C # and Python.

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.

Introduction

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

Naming convention comparison list

A quick comparison list of C # and Python naming conventions.

Identifier C # Python
Package (namespace) PascalCase All lowercase letters
HappyBirthdayhappybirthday
Module PascalCase All lowercase / SnakeCase
HappyBirthdayhappybirthday / happy_birthday
Class PascalCase PascalCase
HappyBirthdayHappyBirthday
Type variable PascalCase PascalCase
HappyBirthdayHappyBirthday
Exceptions PascalCase PascalCase
HappyBirthdayExceptionHappyBirthdayError
Global Variables Pascal SnakeCase
HappyBirthdayhappy_birthday
Parameters (arguments) CamelCase SnakeCase
happyBirthdayhappy_birthday
Method (function) PascalCase SnakeCase
GetHappyBirthdayget_happy_birthday
Variables CamelCase SnakeCase
happyBirthdayhappy_birthday
Constant PascalCase ConstantCase
HappyBirthdayHAPPY_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

[Introduction to Python] I compared the naming conventions of C # and Python.
I want to know the features of Python and pip
I compared the speed of Hash with Topaz, Ruby and Python
I replaced the numerical calculation of Python with Rust and compared the speed
I tried to verify and analyze the acceleration of Python by Cython
I compared the speed of regular expressions in Ruby, Python, and Perl (2013 version)
I compared Java and Python!
I checked out the versions of Blender and Python
I felt that I ported the Python code to C ++ 98.
[Introduction to Python] Basic usage of the library matplotlib
I tried to summarize the string operations of Python
I tried to automate the article update of Livedoor blog with Python and selenium.
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
[Introduction to Sound] Let's arrange the introduction to sounds of python and R ♬-Listen to the sound of the explosion of Nikkei 255-
I tried to compare the processing speed with dplyr of R and pandas of Python
I tried to find the entropy of the image with python
I tried to illustrate the time and time in C language
[Python] I tried to visualize the follow relationship of Twitter
[Introduction to Data Scientists] Basics of Python ♬ Functions and classes
I tried to enumerate the differences between java and python
The story of Python and the story of NaN
[Introduction to Python3 Day 1] Programming and Python
Introduction to Protobuf-c (C language ⇔ Python)
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I compared the calculation time of the moving average written in Python
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
[Python] How to get the first and last days of the month
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I want to output the beginning of the next month with Python
[Python] I thoroughly explained the theory and implementation of logistic regression
I wrote the code to write the code of Brainf * ck in python
[Python] I thoroughly explained the theory and implementation of decision trees
I want to use both key and value of Python iterator
[Introduction to Udemy Python3 + Application] 69. Import of absolute path and relative path
I summarized how to change the boot parameters of GRUB and GRUB2
[Introduction to Udemy Python3 + Application] 12. Indexing and slicing of character strings
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
Convert the result of python optparse to dict and utilize it
I tried to improve the efficiency of daily work with Python
[Introduction to Data Scientists] Basics of Python ♬ Conditional branching and loops
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
[Introduction to Data Scientists] Basics of Python ♬ Functions and anonymous functions, etc.
I compared python3 standard argparse and python-fire
I wrote AWS Lambda, and I was a little addicted to the default value of Python arguments
I didn't know the basics of Python
The Python project template I think of.
Easy introduction of python3 series and OpenCV3
I want to clear up the question of the "__init__" method and the "self" argument of a Python class.
[Introduction to Data Scientists] Basics of Python ♬
An introduction to Python for C programmers
[Python] How to specify the window display position and size of matplotlib
I tried to visualize the age group and rate distribution of Atcoder
What I did to keep track of the humidity and temperature of the archive
[Introduction to Python] How to sort the contents of a list efficiently with list sort
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I tried to get the authentication code of Qiita API with Python.
(Python) I tried to analyze 1 million hands ~ I tried to estimate the number of AA ~
The file name was bad in Python and I was addicted to import
I tried to extract and illustrate the stage of the story using COTOHA