0% found this document useful (0 votes)
47 views3 pages

Interview Questions

Uploaded by

VIKRAMDAVID
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Interview Questions

Uploaded by

VIKRAMDAVID
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Function Overriding

Function overriding is an ability that allows a subclass or child class to


provide a specific implementation of a method that is already provided by one of its
super-classes or parent classes.
Abstract Class
An abstract class can be considered as a blueprint for other classes. It
allows you to create a set of methods that must be created within any child classes
built from the abstract class. A class which contains one or more abstract methods
is called an abstract class.
Operator Overloading
Operator Overloading means giving extended meaning beyond their
predefined operational meaning. For example, operator + is used to add two
integers as well as join two strings and merge two lists. It is achievable because ‘+’
operator is overloaded by int class and str class.
Inheritance
Inheritance is the capability of one class to derive or inherit the properties
from another class.
Single Inheritance: When a child class inherits from only one parent class, it is
called single inheritance. We saw an example above.
Multiple Inheritance: When a child class inherits from multiple parent classes, it is
called multiple inheritance.
Abstraction
Process of handling complexity by hiding unnecessary information from the
user. Abstraction provides a programmer to hide all the irrelevant data/process of
an application in order to reduce complexity and increase the efficiency of the
program.
Encapsulation
The idea of wrapping data and the methods that work on data within one
unit. This puts restrictions on accessing variables and methods directly and can
prevent the accidental modification of data.
Getters And Setters
The main purpose of using getters and setters in object-oriented programs is
to ensure data encapsulation. Private variables in python are not actually hidden
fields like in other object-oriented languages. Getters and Setters in python are often
used when:
We use getters & setters to add validation logic around getting and setting a
value. To avoid direct access of a class field i.e., private variables cannot be
accessed directly or modified by external user.
Append
Adds its argument as a single element to the end of a list. The length of the
list increases by one.
Extend
Iterates over its argument and adding each element to the list and extending
the list. The length of the list increases by number of elements in its argument.

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.

Built-In Data Types

Numeric Types, Sequence Type, Mapping Type, Modules etc.


Pass
The pass keyword represents a null operation in Python. It is generally used
for the purpose of filling up empty blocks of code which may execute during runtime
but has yet to be written. Without the pass statement in the following code, we may
run into some errors during code execution.
Break: The break statement terminates the loop immediately and the control flows to
the statement after the body of the loop.
Continue: The continue statement terminates the current iteration of the statement,
skips the rest of the code in the current iteration and the control flows to the next
iteration of the loop.
Unit Testing
Unit testing means testing different components of software separately. You
are building software that uses three components namely A, B, and C. Now,
suppose your software breaks at a point time. How will you find which component
was responsible for breaking the software? Maybe it was component A that failed,
which in turn failed component B, and this actually failed the software.
Decorators
Decorators in Python are essentially functions that add functionality to an
existing function in Python without changing the structure of the function itself.
They are represented the @decorator_name
Class Method: A class method is a method that is bound to a class rather than its
object. It doesn't require creation of a class instance.
Static method: Much like class methods, but knows nothing about the class and
just deals with the parameters.
Arrays and Lists

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

Self is a keyword in Python used to define an instance of an object of a


class. In Python, it is explicitly used as the first parameter. It helps in distinguishing
between the methods and attributes of a class from its local variables. global,
protected and private attributes.
Global, Protected and Private Attributes
Global variables are public variables that are defined in the global scope. To
use the variable in the global scope inside a function, we use the global keyword.
Protected attributes are attributes defined with an underscore prefixed to their
identifier e.g., _sara. They can still be accessed and modified from outside the
class they are defined in but a responsible developer should refrain from doing so.
Private attributes are attributes with double underscore prefixed to their
identifier e.g., __ansh. They cannot be accessed or modified from the outside
directly and will result in an AttributeError if such an attempt is made.
List and Tuples
Lists and Tuples are both sequence data types that can store a collection of
objects in Python. The objects stored in both sequences can have different data
types. Lists are mutable, tuples on the other hand are immutable objects. This
means that lists can be modified, appended or sliced on the go but tuples remain
constant and cannot be modified in any manner. Lists are represented with square
brackets, while tuples are represented with parenthesis

You might also like