Python Crash Course for Beginners | Python Keywords and Identifiers

Python Crash Course for Beginners | Python Keywords and Identifiers


Python is a high-level programming language that is widely used in various fields including web development, data analysis, and scientific computing. Like any programming language, Python has its own set of reserved words known as keywords, and also a set of user-defined names known as identifiers. In this article, we will take a closer look at Python keywords and identifiers, and how they are used in Python programming.

Python Keywords

Keywords are reserved words in Python that have special meaning and cannot be used as identifiers or variable names. They are used to define the syntax and structure of the Python programming language. There are 35 keywords in Python 3.9.6, including:

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

These keywords have a specific syntax and purpose in the Python programming language. For example, the keyword if is used to define a conditional statement, while the keyword def is used to define a function. It is important to note that these keywords cannot be used as variable names, function names, or any other identifiers.


Identifiers are user-defined names used to identify variables, functions, classes, and other objects in Python. An identifier can be a combination of letters (a-z or A-Z), digits (0–9), and underscore (_). However, an identifier cannot start with a digit.

In Python, the naming convention for identifiers is to use lowercase letters for variable and function names, and uppercase letters for class names. Identifiers can also have a combination of uppercase and lowercase letters.

Let’s take a look at some coding examples to better understand Python keywords and identifiers.

# Example of Python keywords
for i in range(5):

# Example of Python identifiers
my_variable = 10
my_function = lambda x: x**2

class MyClass:

In this code, we use the Python keyword for to define a loop that iterates through a range of numbers. We then define three Python identifiers: my_variable, my_function, and MyClass. my_variable is a variable that holds the value of 10, my_function is a lambda function that returns the square of its input, and MyClass is a class that does nothing (represented by the pass keyword).

It is important to note that we cannot use any of the Python keywords as identifiers in our code. For example, if we try to define a variable with the name if, we will get a syntax error because if is a reserved keyword in Python.

# Example of a syntax error caused by using a Python keyword as an identifier
if = 5

The output of this code will be a syntax error, because if is a reserved keyword in Python and cannot be used as an identifier.

In summary, Python keywords are reserved words in the Python programming language that have special meaning and cannot be used as identifiers. Identifiers are user-defined names used to identify variables, functions, classes, and other objects in Python. It is important to use proper naming conventions for identifiers and to avoid using Python keywords as identifiers in order to avoid syntax errors in our code.


Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.

Learn by Coding: Tutorials on Applied Machine Learning and Data Science for Beginners

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!