Keywords and Identifiers

Python keywords

Python keywords are essentially predetermined and reserved terms within Python programming, each carrying distinct implications for the compiler. The utilization of these keywords as variable names, function identifiers, or any other symbol is prohibited. Their primary role lies in dictating the syntax and fundamental framework of the Python language.

With the exception of “True,” “False,” and “None,” all keywords adhere to lowercase formatting, necessitating exact replication. The comprehensive compilation of these keywords is presented in the subsequent listing.

 Python Keywords List

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

Python Identifiers

A Python Identifier is like a name we give to different things like a variable, a function, a class, or a module. It’s how we recognize these things.

Think about it like naming your pets or toys. You give them names so you can call them when you want to play or interact with them. Similarly, in Python, when we want to use something like a number, a group of instructions, or a special tool, we give it a name, and that’s what we call an identifier.

Sometimes people mix up the terms “variable” and “identifier,” but they’re not the same. Let’s clear things up by understanding what a variable is.

What’s a Variable in Python?

A variable is a bit like a container that can hold different things, and the things it holds can change over time. Imagine having a box where you can put things in and take things out. In Python, a variable is like that box. It’s a place in the computer’s memory where we can put information, like numbers or words. Later, we can take out this information and use it. But just like we put labels on our boxes to know what’s inside, we give a special name to the memory location where the information is stored. This special name is what we call an identifier.

Rules for Giving Names:

There are some rules for picking names (identifiers). First, remember that Python cares about whether letters are uppercase or lowercase. This means that “Name” and “name” are not the same in Python. Now, here are some simple rules for picking names:

  • Names can have a mix of big and small letters, numbers, or an underscore (_). This means you can call something “myVariable,” “variable_1,” or “variable_for_print” – all these names are good in Python.
  • A name can’t start with a number. So, “variable1” is okay, but “1variable” isn’t allowed.
  • Stay away from special symbols like !, #, @, %, $, and so on. Just use letters, numbers, and underscores.
  • A name can be short or long – it’s up to you.
  • There are some extra things to keep in mind, like starting class names with a big letter and using underscores to separate words in long names.

For example, instead of saying “c equals 10,” it’s better to say “count equals 10.” This helps you understand your code even after a long time. Also, if you want to use many words, you can separate them with underscores, like “this_is_a_variable.”

Remember, these rules are important, but there are also some other good habits you can follow.