Keywords and Identifiers in Python

keywords-and-identifiers-in-python

In this module, we will learn about Keywords (reverse words in python) and identifiers (the name which is given to variables or functions) of Python.

Keywords in Python.

In Python, keywords are reserved words. Keywords in python have a special meaning and cannot be used as variable names or identifiers.

These keywords are used to control the flow of a program, define functions, or perform logical operations.

The important thing you need to know is that all the keywords in python are always written in lowercase like if, else, and while.

But False, True, and None are always written in their original form.

Here is a list of all 35 keywords in Python:

whileand if else

and

The important thing you need to know that these keywords are reserved and cannot be used as variable names or identifiers in code.

Identifiers in Python.

After keywords, identifiers are most important thing in python. Basically, identifiers are names given to variables, functions, classes, and other objects. They are used to refer to these objects in the code.

An identifier start with a letter (uppercase or lowercase) or an underscore (_).

In python, identifiers cannot be act as keyword or a reserved symbol. Keywords must be unique within the scope in which it is used.

For example, “variable”, “a”, and “Person” are all valid identifiers in Python.

You can also use a single alphabet as a variable identifier like “a” , “z” and “m” or you can use any other alphabet.

It’s important to have meaningful names for your identifiers to improve the readability of your code.

You want to use, “sum_of_numbers” instead of “sumofnumbers” to improve readability.

Python is case-sensitive, which means that “name” and “Name” are considered two different identifiers.

Rules for Defining Identifier in Python

There are some rules “how to define identifiers in python”:

  • An identifier must start with a letter (uppercase or lowercase) or an underscore (_).
  • It can contain any number of letters, digits, or underscores.
  • An identifier cannot be a keyword or a reserved symbol.
  • Identifiers must be unique within the scope in which they are used.
  • Identifiers can be of any length.

Discover more from Python Mania

Subscribe to get the latest posts sent to your email.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

Related Articles:

Recent Articles:

0
Would love your thoughts, please comment.x
()
x

Discover more from Python Mania

Subscribe now to keep reading and get access to the full archive.

Continue reading