Keyword is a reserved and pre-defined word in python, that have a special content. Keywords are used to define the syntax of coding. The keyword cannot be used as an identifier, function and variable name. All the keywords in python are written in lowercase are expected as true and false. There are 33 keywords in python 3.7.
- And: This is a logical operator and will return true if both the operands are true else will return to false.
- Or: This is a logical operator will return true if anyone of the operand is true else will return to false.
- Not: This is a logical operator will return True if the operand is false else will return false.
- If: Used as a conditional statement.
- Elif: Elif is a condition statement used with if statement the elif statement is executed if the previous statements are not true.
- Else: Else is used with if and elif conditional statement the else block is executed if the condition is not true.ition is not true.
- For: This keyword is created for a loop.
- While: This keyword is created for a while loop.
- Break: This is used to terminate the loop.
- As: This keyword is used as an alternative.
- Def: This keyword is used to define a function.
- Lamba: This keyword is used for defining a anonymous statement.
- Pass: This keyword is a null statement which means that it does nothing.
- Return: It will return to a statement or value and will end the program.
- True: This keyword is a Boolean value.
- False: This keyword is a Boolean value.
- Try: This keyword makes a try-expect statement.
- With: This keyword simplifies exceptional handling.
Exceptional handling:
An exception is an event which occurs while performing a program, which disrupts the normal flow of the program.
In Python when a situation occurs where the python cannot cope with the situation it rises an exception.
An exception is a Python object that represents an error.
- Assert: This keyword is for debugging purposes which checks the correctness of the code.
- Class: Helps us to define a class.
- Continue: This keyword is used to continue to next iteration of the code.
Iteration: Repeated set of statement is called iteration.
- Del: It deletes a reference to the object.
- Except: Used with exceptions, what to do when an exception occurs.
- Finally: This keyword is used with exceptions where the code will be executed no matter an exception occurs or not.
- From: This part is used to import parts in any module.
- Global: This keyword b is used to declare a global variable.
- Import: This keyword is used to import a module.
- In: This keyword is used to check whether a value is in list, tuple, etc or not.
Tuple: Used to invoke multiple statements in a single variable.
- This keyword is used to check whether the two variables are equal or not.
- None: This keyword is a special constant used to denote a null value or a void value.
- Non-local: This keyword is used to declare a non-local variable.
- Raise: This keyword is used to raise an exception.
- Yields: This keyword is used to end a function and return to generator.
Python Identifiers:
- An identifier is used to identify a variable, function, class, module, etc.
- Identifier is a combination of digits and underscores.
- Rules:
- Identifier must begin with a character or underscore then we should input the digit.
- The characters may be alphabets (A-Z, or a-z), digits(0-9), or underscore(_).
- Special characters cannot be used like @, #, $, %, !).
Examples of valid identifiers:
- Var_1
- _var1
- _1_var
- Var_1
Examples of invalid identifiers:
- !prequelcoding1
- @prequelcoding1
- 1_prequelcoding
- Prequelcoding#12
- $Prequelcoding