0% found this document useful (0 votes)
6 views11 pages

Naming Conventions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Naming Conventions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Naming Conventions

Naming conventions

Naming conventions:
o Naming Conventions is a rule to follow as you decide what to name
your identifiers such as class, package, variable, constant, function etc.

o But it is not forced to follow.


Naming Conventions

General rules for python naming conventions:


Rule1: Always give a meaning full name for any of the python objects.
Don’t give names like x, y, or z etc.

Rule2: Don’t give space in between object name instead of using


underscore(_) when there are more than one-word presents.

Rule3: Better to use camelCase only when it makes sense or else try
avoiding more use of camelCase.
Naming conventions

Naming convention for identifiers:


Function:
o We should write the python function name with all lower case characters.
o Do not use uppercase character while naming a function in python.
o Use underscore(_)in between the words instead of space while naming a
function.
Example:
def example_function():
print(“This is the way a function must be used”)
Naming conventions

Naming convention for identifiers:


Variable:
o You must start variable name with an alphabet or underscore(_) character.
o A variable name can only contain Alphanumeric (A-Z, 0-9) and underscore(_).
o You cannot start the variable name with a number.
o You cannot use special characters with the variable name such as $, %, @, #,
&, ^ etc.
o Variable names are case sensitive. For example age and Age are two different
variables.
o Do not use reserve keywords as a variable name for example class, for, def
etc.
Naming conventions

Naming convention for identifiers:


Variable:
Example:
Naming conventions

Naming convention for identifiers:


Class:
o We need to follow the camelCase convention.
o When you are writing any classes for an exception then that name should
end with “Error”.
o If you are calling the class from somewhere or callable then, you can give
a class name like a function.
o The built-in classes in python are with lowercase.
Naming conventions

Naming convention for identifiers:


Class:
Example:
class MyClass
class Hello
class InputError
class ProperClassNamingConvention
Naming conventions

Naming convention for identifiers:


Package:
o You should use all lowercase while deciding a name for a package.
o If there are multiple words in your package name then they should be be
separated by an underscore(_).
o It is always better to use a single word for a package name.
Example:
from mypkg import mod1
from example_package import cars
Naming conventions

Naming convention for identifiers:


Global variable:
o You should use all lowercase while deciding a name for a object.
o If there multiple words in your global variable name then they should be
separated by an underscore(_).
Example:
global my_variable
global user_name
global AGE
Thank You

You might also like