In this tutorial, you will explore the basic introduction about all keywords, the basic building block of the python programming language. You will learn what keywords are, how to identify keywords from other words and their uses .
Python Keywords are special words reserved in python language used for some unique programming purposes. A keyword cannot be used as a variable name, function name, class name, or as any other identifier but can be used for specific purposes. For instance, Python Keyword – ‘break’ is used to break the flow of python code. Hence, ‘break’ cannot be used to name a variable or function or any other entities.
The New Version of python has 35 keywords (reserved words) which contribute a good vocabulary to the python language.
Follow below mentioned easy steps to access the python keyword list in your OS.
Here is a list of the Python keywords. Enter any keyword to get more help.
Python has facilitated numerous ways to find out or to check which words are reserved for keywords. They are listed below:
Based on the usage, Keywords can be categorized as follows.
These keywords are valued-based keywords as they can be used over and over again. These singleton values always reference the same objects.
These keywords are used for computing arithmetic and logical operations.
These keywords are used to control the flow of code by allowing the user to use conditional logic and execute blocks of code that favor the condition.
These keywords are used to create and work with iterations.
Structure Keywords: def, class, with, pass, lambda
Returning Keywords: return, yield
Exception Handling Keywords: try, except, raise, finally, assert
Python keywords and their corresponding activity is described below in a tabular form for easy access. For better understanding and readability keywords starting with uppercase characters are mentioned on the top rows followed by the lowercase keywords. From this, we can realize that Python Keywords are case-sensitive.
|Sl No||Python Keywords||Description|
|1||True||Boolean True; outputs True if the statement is True|
|2||False||Boolean False; outputs False if the statement is False|
|3||None||Indicates a void or null value.|
|4||and||Indicates the function of the logical operator “AND”: returns true only if all operands are true otherwise return false|
|5||or||Indicates the function of logical operator “OR”: return false only if all operands are false otherwise return true|
|6||not||Indicates the function of the logical operator “NOT”: returns the reverse of a given statement or operand.|
|7||is||Used to check if two objects reside in the same memory location or not thus testing the object's identities.|
|8||if||A conditional statement that returns True Result when the condition is encountered correctly.|
|9||else||Determines the next step perform when the condition in a conditional statement (if) is False|
|10||elif||Short form of else-if: Refer if and else|
|11||for||Used to represent looping in python language.|
|12||while||Used to represent looping in python language.|
|13||break||breaks or terminate the loop and moves to the next statement|
|14||continue||Skips the current iteration when a condition is triggered but continues with the remaining iteration in for loop or while loop.|
|15||pass||A null statement used as a placeholder to combat indentation error.|
|16||return||Returns the result to the caller once it terminates the execution of from function call.|
|17||yield||Used in a generator function to return the result.|
|18||try||Tries to catch an exceptional error in the program|
|19||except||Works together with ‘try’ for error and exception handling|
|20||raise||Raises an exceptional error defined by the user.|
|21||finally||Used to ensure the smooth execution of codes even if ‘try’ raises an error or not|
|22||assert||Used as a debugging tool to test a condition: it returns false, an exceptional error will raise and is idle if returns true|
|23||import||Used to import a specific module to the python program.|
|24||from||Used to include a particular section or functionality from the imported module. Always comes with import.|
|25||as||Offers a new name to the imported module.
Eg: import calculator as calc
|26||def||Defines a normal function in python|
|27||lambda||Defines an anonymous or nameless function in python|
|28||class||Defines a class in python|
|29||global||Indicates the scope of a variable throughout the program even if the variable is declared inside a function|
|30||non-local||This indicates the scope of a variable is declared neither locally nor globally. Usually, associate with nested functions.|
|31||with||Explored by content managers for controlling the resources like file or sub-processes or locks by properly exiting no matter if raises an exception|
|32||in||Used to check whether a value is present in a list or a set. Also used in for loop.|
|33||del||Abbreviation of delete. It helps to remove objects present in the python script.|