Introduction

Python is an interpreted language that is widely used for various purposes ranging from web development to scientific computing and automation. In order to write efficient and understandable code in Python, it is essential to follow certain rules and conventions that govern the language. This tutorial will provide an overview of these important rules and naming conventions, including topics such as naming variables,  functions, classes,  packages and modules in Python. Whether you are a beginner or an experienced programmer, this tutorial will be a valuable resource for ensuring your Python code is clean and easy to understand.

Table of Contents :

  • Naming Conventions in Python
  • Naming Conventions for naming Python Classes 
  • Every programming language has its own set of rules and naming conventions. 
  • These rules and conventions are designed to make the code more readable and consistent. 
  • Python has some of the strictest rules and naming conventions of any programming language.
  • Python naming conventions are designed to make code more readable. 
  • Python is case sensitive thus the name my_var is different from My_var
  • Python uses indentation to define code blocks. 

Naming Conventions in Python

Below are the naming conventions for naming Python Variables, Packages, Modules and Functions (Methods) 

  • Names can be a combination of 
    • letters in lowercase (a-z), 
    • uppercase (A-Z), 
    • digits (0-9) and 
    • underscores (_). 
  • The first character must be a letter or an underscore.
  • Keywords cannot be used as names.
  • Words in the name are separated by underscore.
  • White-spaces are not allowed in names.
  • Names cannot have special symbols like !, @, #, $ etc.
  • Names should be in lowercase.

Naming Conventions for naming Python Classes 

  • Class names should begin with an uppercase letter.
  • White-spaces are not allowed in class names.
  • Class Names cannot have special symbols like !, @, #, $ etc.
  • Keywords cannot be used as class names.
  • Class names should be in CamelCase

Prev. Tutorial : Literals

Next Tutorial : Types of operators