Keywords are the special words that are already reserved for some particular purpose in Python. They can not be used as Identifiers.
Keywords are also referred to as Reserved words.
Following are known keywords in Python.
As of Python 3.8, there are thirty-five keywords in Python.
Keywords are used to define the syntax and structure of the Python language.
Keywords are case sensitive. Case Sensitivity defines whether uppercase and lowercase letters are treated as distinct (case-sensitive) or equivalent (case-insensitive).
|as||used to create an alias|
|assert||for debugging purpose|
|break||to break out of python loops|
|class||used for defining classes in Python|
|continue||used to continue the program flow by skipping the current iteration|
|def||used for defining a function/ method|
|del||used for deleting objects in Python|
|elif||Part of the if-elif-else statements|
|else||As stated above|
|except||used to catch exceptions|
|finally||runs a statement when no exception occurs|
|global||specifies a variable scope as global|
|if||used for defining condition|
|import||used to import modules|
|in||checks if specified value is present in an iterable object|
|is||used to test equality|
|lambda||create anonymous functions|
|None||represents a NULL value|
|nonlocal||declare a variable with non local scope|
|not||logical operator to negate a condition|
|or||operator used when either of the given conditions needs to be true|
|pass||actually does not effects the program flow|
|raise||raise an exception|
|return||exits a running function and returns the value|
|try||used in exception handling|
|while||used for defining while loop|
|with||creates a block to make exception handling and file operations easy|
|yield||ends a function and returns a generator object|
Checking the keywords list using code
We can fetch the list of Python Keywords with the help of help() function. Python’s help() function is used to display the documentation of modules, functions, classes, keywords etc. If the help() function is passed without an argument, then the interactive help utility starts up on the console.
Do you know ?
We can put keyword as a variable name in Python, but that’s really a bad bad practice.
That’s all, see you in the next lecture.