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.
TOTAL PYTHON KEYWORDS
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.
and | This is a logical operator it returns true if both the operands are true else returns false. |
Or | This is also a logical operator it returns true if anyone’s operand is true else returns false. |
not | This is again a logical operator it returns True if the operand is false else returns false. |
if | This is used to make a conditional statement. |
elif | Elif is a condition statement used with an if statement the elif statement is executed if the previous conditions were not true |
else | Else is used with if and elif conditional statement the else block is executed if the given condition is not true. |
for | This is created for a loop. |
while | This keyword is used to create a while loop. |
break | This is used to terminate the loop. |
as | This is used to create an alternative. |
def | It helps us to define functions. |
lambda | It is used to define the anonymous function. |
pass | This is a null statement which means it will do nothing. |
return | It will return a value and exit the function. |
True | This is a boolean value. |
False | This is also a boolean value. |
try | It makes a try-except statement. |
with | The with keyword is used to simplify exception handling. |
assert | This function is used for debugging purposes. Usually used to check the correctness of code |
class | It helps us to define a class. |
continue | It continues to the next iteration of a loop |
del | It deletes a reference to an object. |
except | Used with exceptions, what to do when an exception occurs |
finally | Finally is used with exceptions, a block of code that will be executed no matter if there is an exception or not. |
from | The form is used to import specific parts of any module. |
global | This declares a global variable. |
import | This is used to import a module. |
in | It’s used to check if a value is present in a list, tuple, etc, or not. |
is | This is used to check if the two variables are equal or not. |
None | This 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 |
nonlocal | It’s declared a non-local variable. |
raise | This raises an exception |
yield | It ends a function and returns a generator. |
PYTHON IDENTIFIERS
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
OUTPUT
File "<interactive input>", line 1 global = 1 ^ SyntaxError: invalid syntax
We are unable to use special symbols like! @, #, $,%, etc. in our identifier.
a@ = 0
OUTPUT
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.