In Python, reserved words are known as keywords. A keyword cannot be used as a function, identifier or even a variable.
Set 1 keyword of Python
True: This keyword represents a true boolean value. "True" is printed if a statement is true.
False: A boolean false is represented by this keyword. "False" is printed if a statement is false.
Note: It is a unique constant that represents a null or void value. It's vital to understand that 0 does not equate to None in any empty container (e.g., an empty list).
It's an object with the NoneType datatype. There is no way to make multiple None objects and attach them to variables.
and: In Python, and is a logical operator that returns the first false value. If you can't find anything, it returns last.
or: In Python, this is a logical operator. OR return the first True value.
not: The truth value is inverted using this logical operator.
in: This keyword is used to determine whether or not a container has a value. This keyword can also be used to loop through a container.
is: It is used to check object identity, or whether two objects have the same memory location.
Keywords for iteration
For: This keyword is often used to manage the flow of the programme and to loop it.
While: Works in a similar way as "for," which is used to control flow and looping.
Break: The word "break" is often used to control the loop's flow. The statement is used to exit the loop and transmit control to the statement immediately following the loop.
Continue: The command "continue" is often used to control code flow. The keyword bypasses the loop's current iteration but it does not finish it.
Conditional keywords
if: It's a decision-making control statement. Control is forced into the "if" statement block by truth expression.
else: It's a decision-making control statement. Control is forced into the "else" statement block due to a false expression.
Elif: It's a decision-making control statement. It stands for "else if."
Set 2 keywords in Python
Return keywords
Return - The return keyword has been used to exit the function.
Yield - This keyword is similar to the return statement, only it returns a generator.
Class - The class keyword is often used to declare classes that are defined by the user.
With - The with keyword can be used to surround the execution of a code block within context manager-defined methods. In day-to-day programming, this keyword is rarely used.
Pass - In Python, the null statement is called a pass. When this occurs, nothing happens. This has been used as a placeholder to avoid indentation problems.
Lambda - The lambda keyword can be used to create inline yielding functions with no internal statements.
Import - This statement can be used to bring a certain module into the current programme.
From - Usually used in conjunction with import, from can be used to import specific functionality from the module that has been imported.
Exception handling keywords
try: This keyword has been used to handle exceptions and is used in conjunction with the keyword except to catch problems in the code. If there is any form of error, the code in the "try" block is verified, but the block is not executed.
except: As previously stated, this works in conjunction with "try" to catch exceptions.
finally: Regardless of the outcome of the "try" block, the "finally" block is always executed.
raise: The raise keyword can be used to explicitly raise an exception.
assert: This function can be used to help with debugging. Usually used to ensure that code is correct. Nothing happens if a statement is assessed as true, but if it is false, "AssertionError" is issued. A notice with the error, divided by a comma, can also be printed.
Del - To remove a reference to an object, type del. del can be used to delete any variable as well as a list value.
Global - This keyword is used to declare a variable within a function to have a global scope.
Non-local - This keyword is similar to global, but instead of declaring a variable to point to a variable outside the enclosing function, in the scenario of nested functions, it creates a variable to point to a variable from the outside enclosing function.
The fundamental building elements of any Python programme are Python keywords. Understanding how to use them correctly is crucial to increasing your Python abilities and knowledge. You've seen a few items in this post to help you consolidate your understanding of Python keywords and develop more efficient and understandable code.