Looping Constructs in Python: A Guide to for and while Loops

Python Keywords And Identifiers

Python uses reserved and predefined words with specific meanings called keywords. In order to specify the coding syntax, keywords are utilized. The keyword is ineligible for usage as a variable name, function, or identifier. With the exception of True and False, all keywords in Python are written in lower case. Let’s go through each of the 33 keywords in Python 3.7 one by one.

A name used to identify a variable, function, class, module, etc. is an identifier. The identification is made up of underscore and character digits. The identification must begin with a letter or underscore before moving on to a number. A-Z or a-z, an underscore (_), and a number make up the letters (0-9). Special characters (#, @, $,%, and!) shouldn’t be used in identifiers.


The reserved words in Python are called keywords.

The name of a variable, function or any other identifier cannot contain a keyword. They are used to specify the Python language’s grammar and organization.

Keywords in Python are case-sensitive.

In Python 3.7, 33 keywords are available. Over time, this value may change somewhat.

All of the keywords, with the exception of True, False, and None, are lowercase and must be spelled that way. The whole list of keywords is shown below.

andThis is a logical operator it returns true if both the operands are true else returns false.
OrThis is also a logical operator it returns true if anyone’s operand is true else returns false.
notThis is again a logical operator it returns True if the operand is false else returns false.
ifThis is used to make a conditional statement.
elifElif is a condition statement used with an if statement the elif statement is executed if the previous conditions were not true
elseElse is used with if and elif conditional statement the else block is executed if the given condition is not true.
forThis is created for a loop.
whileThis keyword is used to create a while loop.
breakThis is used to terminate the loop.
asThis is used to create an alternative.
defIt helps us to define functions.
lambdaIt is used to define the anonymous function.
passThis is a null statement which means it will do nothing.
returnIt will return a value and exit the function.
TrueThis is a boolean value.
FalseThis is also a boolean value.
tryIt makes a try-except statement.
withThe with keyword is used to simplify exception handling.
assertThis function is used for debugging purposes. Usually used to check the correctness of code
classIt helps us to define a class.
continueIt continues to the next iteration of a loop
delIt deletes a reference to an object.
exceptUsed with exceptions, what to do when an exception occurs
finallyFinally is used with exceptions, a block of code that will be executed no matter if there is an exception or not.
fromThe form is used to import specific parts of any module.
globalThis declares a global variable.
importThis is used to import a module.
inIt’s used to check if a value is present in a list, tuple, etc, or not.
isThis is used to check if the two variables are equal or not.
NoneThis is a special constant used to denote a null value or avoid. It’s important to remember, that 0, any empty container(e.g empty list) does not compute to None
nonlocalIt’s declared a non-local variable.
raiseThis raises an exception
yieldIt ends a function and returns a generator.


A name provided to an entity, such as a class, function, variable, etc., is called an identifier. It aids in separating one thing from another.

Guidelines for identifying words

Identifiers can consist of a mix of lowercase (a to z) or capital (A to Z) characters, numerals (0 to 9), or an underscore ( ). Examples of acceptable names are myClass, var 1, and print this to the screen.

An identification number cannot begin with a digit. Although variable1 is an acceptable name, a variable is not.

Identifying terms cannot be used as keywords.

global = 1


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

We are unable to use special symbols like! @, #, $,%, etc. in our identifier.

a@ = 0


  File "<interactive input>", line 1
    a@ = 0
SyntaxError: invalid syntax

Things to Keep in Mind

A case-sensitive language is Python. This implies that variable and variable are distinct terms.

Give the IDs sensible names at all times. While c = 10 is a legitimate name, stating count = 10 would make more sense and make it simpler to understand what it stands for when you next review your code.

An underscore can be used to separate words, as this is a long variable.

Leave a Reply