KEYWORDS


KEYWORDS

Keywords refer to the reserved words in the Python programming language. The Keyword cannot be used as a variable name, function name, or any other identifier. They are used to define the syntactical structure of the Python programming language. All the keywords in python are mostly in lower case, except True, False & None.

Following are the list of keywords as follows:

True - It mainly represents the Boolean value true that is if the given condition is true, then it returns "True". Non-zero values are also treated as true.

False - It mainly represents the Boolean false; if the condition is considered as false, then it returns to the state of "False". Zero value is also treated as false.

None - It refers to the null value or void. An empty list or zero is treated as none. and - It is mainly a logical operator. It is used to check a multitude of conditions. It returns true if both the conditions are true.

or - It is a logical operator in the Python programming language. It returns true if one of the conditions has its value as true.

not - It is a logical operator and works in inverting the truth value.

assert - This keyword is mainly used as the debugging tool in Python. It checks the efficiency of the code. It raises mainly an AssertionError. If it is found any error in the code and also prints the message with an error.

def - This keyword is used to declare the function in the Python programming language. It is followed by the function name.

class - It is used to represents the class in the Python programming language. The class is considered to be a specific blueprint of the objects. It is considered to be the collection of the variable and the methods.

continue - It is mainly used to stop the execution of the current iteration in a loop and then go on to perform the next iteration.

break - It is used to terminate the execution of the loop and transfers control to the end of the loop.

if - If is used to represent the conditional statement. The if statement decides the execution of a particular block in the code.

else - The else statement is used with the if statement that is when if statement returns false, then the else block is executed in code.

else if - This Keyword is used to check the number of conditions. It is mainly a short form of else-if. If the previous else condition is false, then check until the true condition is discovered.

del - It is mainly used to delete the reference of the object created in a code.

try, except - The try-except is used for exception handling. The exceptions are mainly run-time errors.

raise - The raise keyword is used to go through the exception on their own forcefully.

finally - The final keyword is used to create a block of code that will always be executed no matter if- else block raises the error or not.

for, while – These are iterating loops. The keyword is used to iterate over the sequences like list, tuple, dictionary, string. A while loop is executed until the condition is returned false.

import - The import keyword is mainly used to import modules in the current Python version. The module contains an executable Python code that runs without a mess.

from - This keyword is almost always used to import the specific function or attributes in the current Python script.

return - The return keyword is used to return the result of a function which can be Boolean, string, or integer or none to the called function.

is - This specific keyword is used to check if two or more variables refer to the same object. It returns the true value if they refer to the same object otherwise the keyword returns false.

with - The with keyword is used in the handling exceptions. It makes the code cleaner and more user-friendly. The advantage of using with keyword is that we don't need to call it close().

Example:

#as keyword import calendar as c print(c.month_name[3]) #class keyword class Person: name = "knowledge2life" year = 2021 print(Person.name) #globle kayword def myfunction(): global x x = "knowledge2life" myfunction() print(x)

OUTPUT:

March
knowledge2life
knowledge2life