# Python naming conventions are very important and useful in any programming language.
# Here's a variety of Python naming conventions that we should use while programming in Python.
# Constant naming convention in Python
There are certain rules we need to follow while naming a constant.
Rule-1: Constant name in python should be capitalized always.
Rule-2: If there are multiple words in your constant name then they should be separated by an underscore(_).
# Object naming convention in Python
There are certain rules we need to follow while we are deciding a name for the Object in python.
Rule-1: You should use all lowercase while deciding a name for an Object.
Rule-2: Choose a very short name.
Rule-3: If there are multiple words in your object name then they should be separated by an underscore(_).
# How to choose a function name in Python?
There are certain rules we need to follow while naming a function in Python.
Rule-1: We should write the Python function name with all lower case characters.
Rule-2: Do not use uppercase character while naming a function in python.
Rule-3: Use underscore(_) in between the words instead of space while naming a function.
Example:
def my_function():
print("This is the way we should use the function name")
def critical_function():
print("Better function name")
def new_data():
print("Better function name")
# Variable naming convention in python or What are the variable naming conventions in Python?
# Python naming conventions for variable names are same as function names.
There are some rules we need to follow while giving a name for a Python variable.
Rule-1: You should start variable name with an alphabet or underscore(_) character.
Rule-2: A variable name can only contain A-Z,a-z,0-9 and underscore(_).
Rule-3: You cannot start the variable name with a number.
Rule-4: You cannot use special characters with the variable name such as such as $,%,#,&,@.-,^ etc.
Rule-5: Variable names are case sensitive. For example str and Str are two different variables.
Rule-6: Do not use reserve keyword as a variable name for example keywords like class, for, def, del, is, else, try, from, etc.
# Allowed variable names:
x=2
y="Hello"
mypython="PythonGuides"
my_python="PythonGuides"
_my_python="PythonGuides"
_mypython="PythonGuides"
MYPYTHON="PythonGuides"
myPython="PythonGuides"
myPython7="PythonGuides"
# Variable name not Allowed
7mypython="PythonGuides"
-mypython="PythonGuides"
myPy@thon="PythonGuides"
my Python="PythonGuides"
for="PythonGuides"
# How to name a Class in python
Python naming conventions for classes are the same as any other programming languages like C#.net or C++.
# There are certain rules we need to follow while we are deciding a name for the class in python.
# The program really looks cool when you will give a proper name for the class because the Program starts with the class.
Rule-1: We need to follow the camelCase convention
Rule-2: When you are writing any classes for an exception then that name should end with “Error“.
Rule-3: If you are calling the class from somewhere or callable then, in that case, you can give a class name like a function.
Rule-4: The builtin classes in python are with lowercase.
# Example:
class MyClass
class Hello
class InputError