General

Python Keywords

Python Keywords

Python Keywords

The Python Keyword module is used to avail the list of all the keywords. The reserved words cannot be used as a variable name.

Please find the list below

  •  import keyword
  •  keyword.kwlist

‘And’ ,’as’,’assert’,’break’,’class’,’continue’,’def’,’del’,’elif’,’else’,’except’,’exec’,’finally’,’for’

‘From’,’global’,’if’,’import’,’in’,’is’,’lambda’,’not’,’or’,’pass’,’print’,’raise’,’return’,’try’,’while’

‘With’,’yield’.

  • And – for combining the conditions.

Example: 

5 and 0 => false
  • As – used for creating alias

Example:

import numpy as np
  • Assert – used for debugging purposes

Example:

a = 10
assert a > 20
  • Break – to take the control out of the loop.
  • Class -for defining a class:

Example:

class employe:
  • Continue – to take the control back to the loop.
  • Def – for defining a function.
  • Del – for deleting a reference object.

Example:

x = 10 del x print(x) nameerror
  • Elif – conditional statement.
  • Else – conditional statement
  • Except – exceptional handling condition
  • Finally – finally block which always gets executed.
  • For – looping condtion
  • From – imports only some function.

    Example:

from math import sin
  • Global – for declaring global variables
  • If – conditional statement
  • Import – for importing module.
  • In – for checking whether a string contains in a string or list
  • Is – this is used for testing object identity.
  • Lambda – for writing anonymous fuctions.
  • Not – not with true means false/
  • Or – either one of them is true then it is true.
  • Pass – it generaly does nothing. Simply to state pass the line
  • Print – for printing the condition
  • Raise – for raising an exception.
  • Return – for returning some value from function.
  • Try – for exceptional handling.
  • While – for looping purpose.
  • With – used in opening the file.
  • Yield – used inside a function to return statement but it returns a generator.

Click Here-> Get Python Training with Real-time Projects

Eagle Academy WhatsApp