Interview Questions
Interview Questions
Exceptions
Exception is the run-time errors that are unable to handle to Python script. If
we do not handle the exception, the interpreter doesn't execute all the code that
exists after the exception. ZeroDivisionError, NameError, IndentationError are
common exceptions.
We must place that code in the try block. The try block must be followed with
the except statement, which contains a block of code that will be executed if there is
some exception in the try block. We can also use the else statement with the try-
except statement.
Arrays can only contain elements of same data types i.e.; data type of array
should be homogeneous and consumes far less memory than lists.
Lists can contain elements of different data types i.e.; data type of lists can
be heterogeneous. It has the disadvantage of consuming large memory.
__init__
__init__ is a constructor method in Python and is automatically called to
allocate memory when a new object/instance is created. All classes have
a __init__ method associated with them. It helps in distinguishing methods and
attributes of a class from local variables.
Self