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.
|This is a logical operator it returns true if both the operands are true else returns false.
|This is also a logical operator it returns true if anyone’s operand is true else returns false.
|This is again a logical operator it returns True if the operand is false else returns false.
|This is used to make a conditional statement.
|Elif is a condition statement used with an if statement the elif statement is executed if the previous conditions were not true
|Else is used with if and elif conditional statement the else block is executed if the given condition is not true.
|This is created for a loop.
|This keyword is used to create a while loop.
|This is used to terminate the loop.
|This is used to create an alternative.
|It helps us to define functions.
|It is used to define the anonymous function.
|This is a null statement which means it will do nothing.
|It will return a value and exit the function.
|This is a boolean value.
|This is also a boolean value.
|It makes a try-except statement.
|The with keyword is used to simplify exception handling.
|This function is used for debugging purposes. Usually used to check the correctness of code
|It helps us to define a class.
|It continues to the next iteration of a loop
|It deletes a reference to an object.
|Used with exceptions, what to do when an exception occurs
|Finally is used with exceptions, a block of code that will be executed no matter if there is an exception or not.
|The form is used to import specific parts of any module.
|This declares a global variable.
|This is used to import a module.
|It’s used to check if a value is present in a list, tuple, etc, or not.
|This is used to check if the two variables are equal or not.
|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
|It’s declared a non-local variable.
|This raises an exception
|It 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.