DEV Community

loading...

General Naming Conventions for Python

serhatteker profile image Serhat Teker Originally published at tech.serhatteker.com on ・1 min read
  1. Class names should follow the UpperCaseCamelCase convention,
  2. Functions, variables and attributes should be all lowercase and sparated by an underscore (a.ka. snake_case),
  3. Non-public/protected attributes should begin with a single underscore,
  4. Use double underscore for private attributes.
class MyPythonClass:

  def regular_attribute(self):
    print("Hello Python!")

  def _protected_attribute(self):
    print("Hello Python!")

  def __private_attribute(self):
    print("Hello Python!")
Enter fullscreen mode Exit fullscreen mode

For more info: PEP 8 -- Style Guide for Python Code

All done!

Discussion (0)

pic
Editor guide