Python Keywords and Identifiers

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.
  1. And: This is a logical operator and will return true if both the operands are true else will return to false.
  1. Or: This is a logical operator will return true if anyone of the operand is true else will return to false.
  2. Not: This is a logical operator will return True if the operand is false else will return false.
  3. If: Used as a conditional statement.
  4. Elif: Elif is a condition statement used with if statement the elif statement is executed if the previous statements are not true.
  5. 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.
  6. For: This keyword is created for a loop.
  7. While: This keyword is created for a while loop.
  8. Break: This is used to terminate the loop.
  9. As: This keyword is used as an alternative.
  10. Def: This keyword is used to define a function.
  11. Lamba: This keyword is used for defining a anonymous statement.
  12. Pass: This keyword is a null statement which means that it does nothing.
  13. Return: It will return to a statement or value and will end the program.
  14. True: This keyword is a Boolean value.
  15. False: This keyword is a Boolean value.
  16. Try: This keyword makes a try-expect statement.
  17. 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.

  1. Assert: This keyword is for debugging purposes which checks the correctness of the code.
  2. Class: Helps us to define a class.
  3. Continue: This keyword is used to continue to next iteration of the code.
Iteration: Repeated set of statement is called iteration.
  1. Del: It deletes a reference to the object.
  2. Except: Used with exceptions, what to do when an exception occurs.
  3. Finally: This keyword is used with exceptions where the code will be executed no matter an exception occurs or not.
  4. From: This part is used to import parts in any module.
  5. Global: This keyword b is used to declare a global variable.
  6. Import: This keyword is used to import a module.
  7. 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.
  1. This keyword is used to check whether the two variables are equal or not.
  2. None: This keyword is a special constant used to denote a null value or a void value.
  3. Non-local: This keyword is used to declare a non-local variable.
  4. Raise: This keyword is used to raise an exception.
  5. 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:
  1. Var_1
  2. _var1
  3. _1_var
  4. Var_1
     Examples of invalid identifiers:
  1. !prequelcoding1
  2. @prequelcoding1
  3. 1_prequelcoding
  4. Prequelcoding#12
  5. $Prequelcoding
Go

Scroll to top