The focus of this lesson is to understand the concepts of Keywords (Reserved Words) and Identifiers in Python Programming Language. In this lesson, we will discuss both Keywords and Identifiers one by one. So stick with me.
In Python Programming Language when we assign a name to a variable to identify it so we can call that variable by the name, in this case, an Identifier. We use it to identify our variable, class, function or other kinds of objects.
It is strictly followed by Python that every identifier must start with any letter from (A to Z) or (a to z) or if you want you can use ( _ ) underscore symbol followed by one or more letters or numeric digits from (0 to 9). Check out the below identifier example. All of these examples are valid.
myWorld, x_1 and walk_into_pc
In Python Language, the use of punctuation marks for example symbol @, $ and % for identifier name is not allowed. See the invalid examples below.
@xy = 123
In Python, HelloWorld and helloworld are two different identifiers because it is a case sensitive language.
Here are some naming rules or you can say a naming convention for setting the names of identifier, class or functions which are as follows:
- In Python whenever we want to declare a name for a class it must start with an uppercase letter. All other identifiers start with a lowercase letter.
- If you want to make any identifier private starts its name with any letter with a single leading underscore indicates that the identifier is private.
- If you want to make identifier double private you must start it with any letter and two leading underscores to show it as double private.
- An identifier is called language-defined two trailing underscores are present at the end of the identifier.
Keywords in Python Programming Language
There are some specific keywords or words in Python Programming Langauge that cannot be used as an identifier or variable they have an only specific function to perform. In the following table, all the reserve words have shown. Because Python is case sensitive language so one should type all the keywords as it is shown in the table below.
As you are a beginner in Python Programming Language or if you don’t have any prior programming knowledge these words maybe cause confusion for you but as you go further deep in programming you will eventually get familiar to these words. So, keep going and keep programming until you succeed.