Advertisement



< Prev
Next >



Python Identifiers and Keywords



Python language has specified some rules for naming identifiers i.e. names given to variables, functions, classes, modules, etc. These rules are as follows :



Python Naming Conventions


Python language has also specified some naming conventions for identifier i.e. names given to variables, functions, classes, modules, etc. Some of the general naming conventions are as follows:

Identifiers Convention
Variable Name
A variable name should be in lowercase and a multiple word variable name is separated by underscore (_).

Function Name
A function name should be in lowercase alphabets and a multiple word variable name is separated by underscore (_)
.
Class Name
A class name should be in CamelCase(where every first alphabet of a word is in uppercase, with no space or underscore in between multi-word class name.

Module Name
A module name should be in lowercase alphabets and a multi-word module name could be separated by an underscore (_).

Module Constant
A module constant should be in uppercase alphabets, where multi-word constant names are separated by an underscore(_).


Note: Not following these naming conventions while naming an identifier won't raise any error, but still, it is good to follow the naming conventions of Python when coding in it and it also improves the readability of a code.




An example of identifiers in a program :


Let us see a program with a set of valid identifiers.

# Python - Valid identifiers following naming conventions

size = 1000;
ink_price = 9.59;
string1 = 'a'
String1 = 'Have a beautiful life and keep smiling!'

print('Value referenced by variable size is : ', size)
print('Value referenced by variable ink_price is : ', ink_price)
print('Value referenced by variable string1 is : ', string1)
print('Value referenced by variable string2 is : ',  String1)


Output


Value referenced by variable size is :  1000
Value referenced by variable ink_price is :  9.59
Value referenced by variable string1 is :  a
Value referenced by variable string2 is :  Have a beautiful life and keep smiling!



Advertisement




  • Keywords in Python


  • Keywords are the special words whose meaning is already defined in Python programming language. Keywords in Python are also known as reserved words because the name of any keyword cannot be used for an identifier such as variable, function, class name, etc in a Python program. There are about 32 keywords defined in Python. Let's see a table of these keywords.

    keywords keywords keywords keywords
    False None True and
    class continue del def
    global for from finally
    is lambda nonlocal not
    with while return try
    as elif if yield
    or assert else import
    pass break except in
    raise





    Please share this article -





    < Prev
    Next >
    < Data Types in Python
    Python variables and constants >



    Advertisement

    Please Subscribe

    Please subscribe to our social media channels for daily updates.


    Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




    Advertisement



    Notifications



    Please check our latest addition

    C#, PYTHON and DJANGO


    Advertisement