Sitemap
Analytics Vidhya

Analytics Vidhya is a community of Generative AI and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Python Keywords And Identifiers

3 min readJan 18, 2021

--

Every programming language has pre-given keywords which are reserved words when it comes to using the particular language. Identifiers are the words that the programmer can put according to his willing to identify the variables, functions, classes, etc. Do not get confused, just keep reading and you will get the idea properly in the end of this article.

Python Keywords

Let me use the word “reserved” in front of the words which are called keywords in Python. They are reserved, which means you can’t use them willingly for everything. To make it easy to understand, let’s say that there are some rules and regulations to use the keywords.

There are 35 keywords in Python 3.7. (This number can be vary slightly over the course of time.)

In Python, keywords are case sensitive. It means the keywords treat differently depending on whether it is in capitals or lower-case text. All the keywords except True, False and None are written in lower-case letters. Here are the list of all the keywords you are to use with Python coding.

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

Wait! Don’t try to figure out the meaning of these words and where to use them when coding at the first sight. For now, just remember that these are the keywords in Python and they are case sensitive. That’s enough for now.

Python Identifiers

It can be kept in mind that identifiers are the names you can put for a particular class, function, variable, etc. For instance, let’s take a school and I’m going to introduce a group of students who are in grade 10 A class. 10 A is the identifier I put to recognize that particular class from others and inside that school there is only one 10 A class. When it comes to Python identifiers, it is similar to the above example for why we use identifiers in our codes.

Get Nirushi Wijesiri’s stories in your inbox

Join Medium for free to get updates from this writer.

When you put a name as an identifier for something, there are few rules that you have to follow.

  1. An identifier can be a combination of uppercase letters (A to Z), lowercase letters (a to z), numbers (0 to 9) and the underscore (_). Here are some valid identifiers you can use when you are coding.
NUMBER1
number1
Number1
numBer1
number_1
num_ber_1

2. An identifier cannot be started with a digit (number).

1number, 1_number are invalid identifiers. 

3. Keywords cannot be used as identifiers. (All the keywords that are used in Python were mentioned above. If you missed them scroll up and update yourself!)

For instance, if we identify a variable and name it as “lamba”, we will show an error as follows.

lamba=1

Output

File "<interactive input>", line 1
lamba = 1
^
SyntaxError: invalid syntax

4. We can’t use special symbols like !, @, #, $, %, etc. in the identifier. (It is easy to remember that the only special character that you are allowed to use in the identifiers is the underscore (_) )

For example, if we identify a variable as “#value”, it will show an error as follows.

#value=2

Output

File "<interactive input>", line 1
#value= 0
^
SyntaxError: invalid syntax

5. An identifier can be of any length.

Here we have come to the end of this part. In the end what you have to keep in your mind is that keywords are the reserved words in Python and identifiers are the names that you can put for the variables, classes, functions, etc. And the very easy RULES! Easy-peasy! It’s time to code then! Let’s code in Python and go forward! Good luck guys!

--

--

Analytics Vidhya
Analytics Vidhya

Analytics Vidhya is a community of Generative AI and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com