0% found this document useful (0 votes)
7 views

Python

Python is a high-level, interpreted, and dynamically-typed programming language known for readability, easy-to-learn syntax, and versatility. It can be used for a wide range of tasks including web development, data analysis, machine learning, scientific computing, and more due to its vast collection of libraries.

Uploaded by

Kousik Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python

Python is a high-level, interpreted, and dynamically-typed programming language known for readability, easy-to-learn syntax, and versatility. It can be used for a wide range of tasks including web development, data analysis, machine learning, scientific computing, and more due to its vast collection of libraries.

Uploaded by

Kousik Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Curated by Heemali Chaudhari

What is Python? What are the benefits of using Python?


Python is a high-level, interpreted, and dynamically-typed
programming language. Python is known for its
readability, easy-to-learn syntax, and versatility, making it
a great choice for beginners and experts.

Benefits:
Easy to learn: Python has a simple and straightforward
syntax, making it easy to learn and write code, even for
those who are new to programming.

Versatile: Python can be used for a wide range of tasks,


including web development, data analysis, machine
learning, scientific computing, and more.

Plenty of libraries: Python has a vast collection of libraries


and modules, which makes it easier to perform complex
tasks without having to write code from scratch.

Good for prototyping: Python's simple syntax and fast


development time make it a great choice for prototyping
and testing ideas.

01 | Heemali Chaudhari
What is a dynamically typed language?
A dynamically typed language is a programming language
where the type of a variable is determined at runtime,
rather than at compile time. This means that the type of a
variable can change during the execution of a program,
and that variables can be assigned values of different types
during their lifetime.

For example, in a dynamically typed language like Python,


you can assign an integer value to a variable and then later
assign a string value to the same variable. This is in
contrast to statically typed languages like C or Java, where
the type of a variable must be declared when the variable
is created, and the type cannot be changed afterwards.

Dynamically typed languages like Python offer greater


flexibility and can simplify the development process, as
they allow developers to focus more on the logic of their
programs and less on the declaration of data types.
However, this flexibility can also lead to runtime errors, as
type mismatches can occur without being detected by the
compiler.

02 | Heemali Chaudhari
What is PEP 8 and why is it important?
PEP 8 is the style guide for writing Python code. It was
created to ensure that Python code is written in a consistent
and readable manner. It provides guidelines for naming
conventions, indentation, line lengths, and other aspects of
coding style.

PEP 8 is important for several reasons:


Consistency: By following PEP 8, you can ensure that your
code is consistent with the coding style used by the vast
majority of Python developers. This makes it easier for
others to read and understand your code, and helps to avoid
potential coding conflicts when working on larger projects.

Readability: PEP 8 is designed to promote readability,


making it easier to understand code and avoid common
coding pitfalls.

Collaboration: PEP 8 helps to promote collaboration and


sharing within the Python community by providing a
standard coding style that everyone can follow.

Maintenance: Code that is written in accordance with PEP 8


is easier to maintain and update, as it is more readable and
less prone to errors.

03 | Heemali Chaudhari
What are lists and tuples? What is the key difference
between the two?

Lists are defined using square brackets [], and are


mutable, meaning that you can add, remove, or modify
items in the list after it has been created. Lists are also
dynamic, meaning that the size of a list can change as you
add or remove items.

Tuples, on the other hand, are defined using parentheses ()


and are immutable, meaning that once a tuple has been
created, you cannot change its contents. Tuples are also
fixed-size, meaning that their size cannot be changed after
creation.

The key difference between lists and tuples is that lists are
mutable and tuples are immutable. This means that lists
can be changed, while tuples cannot. Because tuples are
immutable, they are often used to store values that are
constant and should not be changed, such as a collection of
data that represents a point in space, a date, or a color.

04 | Heemali Chaudhari
What is pass in Python?
In Python, the "pass" statement is a placeholder statement
that does nothing. It is used in situations where a
statement is required syntactically, but no action needs to
be performed. For example, when you define an empty
class, you can use the "pass" statement to prevent the
interpreter from raising an error.

The "pass" statement is a useful tool when you need to


include a statement in your code, but don't want it to
perform any action. It acts as a placeholder for future
code, and helps ensure that your code remains
syntactically correct.

05 | Heemali Chaudhari
What are modules and packages in Python?
In Python, modules and packages are ways to organize and
structure your code into reusable and manageable units.

A module is a single Python file that contains Python


definitions and statements. Modules provide a way to
separate your code into logically organized and reusable
components, making it easier to maintain and reuse your
code. For example, you might have a module that defines a
set of functions, a module that defines a set of classes, or a
module that defines a set of variables.

A package is a collection of modules that are organized in


a directory structure. Packages provide a way to group
related modules together, making it easier to manage and
distribute your code. For example, you might have a
package that contains modules for working with image
files, a package that contains modules for working with
database connections, or a package that contains modules
for working with web services.

06 | Heemali Chaudhari
What are global, protected and private attributes in
Python?
Global Attributes: Attributes that are declared outside of
any class or function are considered to be global
attributes. They are accessible from anywhere in the code,
and can be modified from any scope. Global attributes are
usually denoted by capital letters, for example:
GLOBAL_VARIABLE.

Protected Attributes: Attributes that are prefixed with an


underscore (e.g. _protected_attribute) are considered to be
protected. This is a convention used to indicate that the
attribute should not be accessed directly from outside the
class, but can be accessed from within subclasses.

Private Attributes: Attributes that are prefixed with two


underscores (e.g. __private_attribute) are considered to be
private. This is a convention used to indicate that the
attribute should not be accessed directly from outside the
class. When a private attribute is accessed, its name is
mangled to include the class name, making it difficult to
access from outside the class. For example, the private
attribute __private_attribute would be mangled to
_ClassName__private_attribute.

07 | Heemali Chaudhari
What is the use of self in Python?

In Python, the keyword self is used to refer to the instance


of an object within a class method. It is used to access the
attributes and methods of the current object.

Here's an example of how self is used in a class:

In this example, the __init__ method uses self to set the


name and age attributes of the object being created. The
say_hello method uses self to access the name and age
attributes of the current object.

When you call a method on an object, Python


automatically passes the object instance as the first
argument to the method, which is usually referred to as
self. This allows you to access the attributes and methods
of the object from within the method.

08 | Heemali Chaudhari
What is break, continue and pass in Python?
break, continue, and pass are keywords in Python that are
used to control the flow of a loop. Here's a brief
explanation of each:

The break keyword is used to exit a loop prematurely.


When a break statement is encountered, the loop is
immediately terminated and control is transferred to the
first statement following the loop.

The continue keyword is used to skip the current iteration


of a loop and move on to the next iteration. When a
continue statement is encountered, control is immediately
transferred to the next iteration of the loop, without
executing any remaining statements in the current
iteration.

The pass keyword is a placeholder that does nothing. It is


used when you need a statement for syntactic reasons, but
don't want any code to be executed.

09 | Heemali Chaudhari
What is slicing in Python?
Slicing in Python is a way to get a part of a list, a string, or
an array by specifying the start and end points. It's like
cutting a piece of a long rope, or a portion of a big pizza.
You can tell Python exactly where you want to start
cutting, and where you want to stop. Slicing is a useful way
to extract parts of a large data structure and work with
smaller, more manageable pieces.

What is the difference between Python Arrays and lists?


In Python, both arrays and lists can store collections of
items, but there are some important differences between
them:
Built-in Functions: Lists have more built-in functions and
methods available than arrays. For example, lists have the
append() method to add items to the end of the list, while
arrays don't.
Performance: Arrays are more efficient than lists for
numerical operations, but lists are more flexible for
inserting and deleting items, and for working with
heterogeneous data.
Data Type: Arrays must contain items of the same data
type, whereas lists can contain items of different data
types.

10| Heemali Chaudhari


What are Python namespaces? Why are they used?
In Python, a namespace is a container that holds a set of
identifiers, i.e., names that correspond to objects such as
variables, functions, and classes. Namespaces are used to
prevent naming conflicts between different objects in a
program, allowing you to use the same name for different
objects in different parts of your code.

What are decorators in Python?


In Python, a decorator is a special type of function that takes
another function as input and returns a modified version of
that function. Decorators allow you to add additional
functionality to existing functions or classes without
modifying their code. They are a powerful and flexible tool
that can be used to extend and modify the behavior of
functions and classes in your code.

What is lambda in Python? Why is it used?


In Python, a lambda function is a small anonymous function
that can take any number of arguments, but can only have
one expression. The expression is evaluated and returned
when the function is called. The lambda keyword is used to
create a lambda function. Lambda functions are a concise
and readable way to define short, throwaway functions in
Python, and they can be used to make your code more concise
and expressive.

11 | Heemali Chaudhari
What is Scope Resolution in Python?
Scope resolution in Python refers to the process of determining
the namespace in which a variable or object is defined. Python
uses a scope hierarchy to determine the scope of an identifier
(variable, function, class, etc.).

There are two main types of scopes in Python: global scope and
local scope.

Global scope: The global scope is defined at the top level of a


module and includes all identifiers that are defined outside of
any functions or classes. Identifiers in the global scope are
available throughout the module and can be accessed from any
part of the code.

Local scope: Local scopes are created within functions and


classes and include all identifiers defined within them.
Identifiers in local scopes are only accessible within the function
or class in which they are defined and are not accessible from
outside of that scope.

When you access an identifier, Python searches for it in the local


scope first and then, if it's not found, in the enclosing scope. If
it's still not found, Python continues searching in the global
scope and then in any imported modules. This process is called
scope resolution.

12 | Heemali Chaudhari
What is pickling and unpickling?
In Python, pickling and unpickling are the processes of
converting a Python object hierarchy into a byte stream,
and vice versa. The term "pickling" comes from the word
"pickle," which means to preserve food by storing it in a
jar with vinegar.

Pickling is used to store a Python object hierarchy (e.g., a


list, a dictionary, or a custom object) in a byte stream
format, which can be saved to disk, sent over a network, or
stored in a database. The byte stream can then be
recovered using the "unpickling" process to recreate the
original object hierarchy.

Pickling and unpickling are useful for preserving the state


of a Python program across multiple runs, for transferring
data between processes or over a network, and for storing
complex data structures in a database. However, it's
important to be cautious when unpickling data from
untrusted sources, as malicious code can be included in the
byte stream and executed when unpickled.

13 | Heemali Chaudhari
What are generators in Python?
Generators are a special type of iterator in Python, used to
generate a sequence of values one at a time, instead of
generating all the values at once in a data structure like a list
or a tuple. The main advantage of using generators is
memory efficiency, as the values are generated one at a time
as they are needed, instead of being stored in memory all at
once.

How are arguments passed by value or by reference in


python?
In Python, arguments are passed by reference, meaning that
the function receives a reference to the object, not a copy of
the object itself. This means that any changes made to the
argument inside the function will affect the original object,
and persist after the function has completed.

However, it's important to note that Python does have some


data types, such as numbers and strings, that are immutable,
meaning that their values cannot be changed. In this case,
when a function receives an immutable object as an
argument, any changes to that object will actually result in a
new object being created, rather than modifying the original
object.

14 | Heemali Chaudhari
Explain split() and join() functions in Python?
The split() and join() functions are string methods in
Python used to manipulate strings.

The split() function is used to split a string into a list of


substrings based on a specified separator. For example, if
you have a string "Hello, World!" and if you use the split()
function with a comma as the separator, the function will
return a list ["Hello", " World!"].

The join() function is the opposite of split(). It is used to


join a list of strings into a single string, using a specified
separator. For example, if you have a list ["Hello", "
World!"] and you use the join() function with a comma as
the separator, the function will return the string "Hello,
World!".

What are negative indexes and why are they used?


Negative indexes are used to simplify access to elements at
the end of a sequence. For example, if you want to access
the last element of a list, you can use an index of -1 instead
of having to calculate the length of the list and then
subtract 1. This can make the code more readable and
concise.

15 | Heemali Chaudhari
How do you access parent members in the child class?
In Python, you can access parent class members in the
child class using the super() function. The super() function
returns a temporary object of the parent class, allowing
you to call its methods.

Differentiate between new and override modifiers.

New: "The new keyword hides the definition of the base


class method and gives a new definition in the derived
class."

As we all know, Override implements Polymorphism.


Which says I want to use the same method but in various
classes with the same signature of methods. So let's see
why we need override and how we can use it in our
applications.

16 | Heemali Chaudhari
What is init method in python?
"init" is a special method in Python classes, also known as
a constructor. It is automatically called when an object of
the class is created, and it is used to initialize the attributes
of the class.

What are the new features added in the newest Python


version?
Structural Pattern Matching: This new feature allows you
to perform powerful and concise matching of data
structures, like tuples and lists, with pattern matching
syntax.

Vectorcall: A new calling protocol for fast calling of built-


in functions and methods with improved performance.

Improved Type Hints: Several improvements have been


made to the type hint system, including support for
Structural Pattern Matching and improved error
messages.

Function Signature Changes: A few changes have been


made to the signature of built-in functions to improve
consistency and functionality.

17 | Heemali Chaudhari
What are python modules?
In Python, a module is a file that contains definitions and
statements. A module can define functions, classes, and
variables, and it can also contain executable statements.
Modules can be imported into other modules or into the main
module (the module that is executed when you run a script).

The purpose of modules is to organize related code into


reusable and maintainable units. By dividing your code into
modules, you can reduce the complexity of your code and
make it easier to understand, maintain, and reuse.

Name some commonly used built-in modules in Python?


os: This module provides a way to interact with the operating
system, such as reading or writing to the file system,
executing shell commands, and manipulating environment
variables.

random: This module provides functions for generating


pseudo-random numbers and for shuffling sequences
randomly.

datetime: This module provides classes for working with


dates and times, such as calculating the difference between
two dates, formatting dates as strings, and parsing strings
into dates.
18 | Heemali Chaudhari
Is python case sensitive?
Yes, Python is case sensitive. This means that the names of
variables, functions, and classes, as well as the names of
keywords and built-in functions, must be written in a
consistent case throughout your code. For example, the code
will result in a NameError if the names of the variables are
not written in a consistent case.

What are functions in Python?


In Python, a function is a block of organized, reusable code
that performs a specific task. Functions allow you to
encapsulate a piece of code and call it multiple times from
different parts of your program, without having to repeat the
code. Functions are defined using the def keyword, followed
by the function name and a set of parentheses that may
include parameters. The code inside the function is indented
and is executed when the function is called.

How can you randomize the items of a list in place in Python?


In Python, you can use the random module's shuffle function
from the random module to randomize the items of a list in
place. This will produce a random order of the items in the
list each time you run the code. Note that shuffle modifies the
list in place and does not return a new list.

19 | Heemali Chaudhari
What are docstrings in Python?
In Python, docstrings are strings that provide documentation for
a module, function, class, or method. They are placed at the
beginning of the code block, inside triple quotes (either single or
double quotes), and serve as the first line of documentation for
the code.

Docstrings are optional but highly recommended, as they


provide valuable information to other programmers (including
yourself) who are reading the code. They are also used by
various tools, such as the help function and automatic
documentation generators, to extract and display information
about your code.

What is a dictionary in Python?


In Python, a dictionary is an unordered collection of key-value
pairs, where each key is unique and used to retrieve its
associated value. Dictionaries are implemented as hash tables
and are optimized for fast lookup and retrieval of values based
on their keys.

Dictionaries are created using curly braces {} or the dict


constructor, with keys and values separated by colons :.
Dictionaries are very useful in many scenarios, such as counting
the frequency of words in a text, storing confiration settings, and
more.

20 | Heemali Chaudhari
What does len() do?
The len() function in Python returns the number of
elements in a sequence (such as a string, list, tuple, etc.).

What advantages do NumPy arrays offer over (nested)


Python lists?
Speed: NumPy arrays are much faster than nested Python
lists, due to their highly optimized C implementation.

Memory Efficiency: NumPy arrays use less memory than


nested Python lists, as they store data in a contiguous
block of memory.

Convenience: NumPy arrays are more convenient to use


than nested Python lists as they provide more advanced
operations and functions.

Compatibility: NumPy arrays are compatible with many


other scientific computing libraries and functions, making
it easier to integrate them into complex data processing
pipelines.

21 | Heemali Chaudhari
Does Python have OOps concepts?
Yes, Python supports Object-Oriented Programming (OOP)
concepts such as classes, objects, inheritance, polymorphism,
and encapsulation.

How is Multithreading achieved in Python?


Multithreading in Python can be achieved through the threading
module. The Thread class in the threading module provides a
way to create and run threads in a Python program. To create a
new thread, you can create a new instance of the Thread class
and pass a function or method to be executed as the thread's
target.

What are Python libraries? Name a few of them.


Python libraries are pre-written collections of code that provide
a set of functionalities and can be used to perform specific tasks
in a Python program. They are designed to make it easier for
developers to perform complex operations and provide a faster
way to implement common tasks.

A few popular Python libraries are:


NumPy: for numerical computing with arrays
Pandas: for data manipulation and analysis
Matplotlib: for data visualization
SciPy: for scientific computing
scikit-learn: for machine learning and data analysis
TensorFlow: for machine learning and deep learning

22 | Heemali Chaudhari
What is split used for?
In Python, the split() method is used to split a string into a
list of substrings based on a specified separator. The
separator can be any character, and by default, it is
whitespace. The resulting substrings are stored in a list,
and the list is returned as the output.

What is the difference between OOP and SOP?


Object-Oriented Programming (OOP) and Structured
Programming (SOP) are two different software
development approaches. In OOP, the emphasis is on
creating objects that encapsulate data and behavior,
whereas in structured programming, the focus is on
breaking down a program into smaller, well-structured
parts that can be easily understood and maintained. In an
OOP approach, objects interact with each other through
methods and messages, whereas in structured
programming, control flow structures like if-else
statements and loops are used to control the execution of a
program. Both approaches have their own advantages and
disadvantages, and the choice between the two often
depends on the specific requirements of a project.

23 | Heemali Chaudhari
Why use OOPs?
OOP is a popular programming approach because it offers
several benefits for software development. Firstly, OOP
provides a way to organize code into reusable and modular
components, which makes it easier to maintain and extend
the code over time. Additionally, OOP enables developers
to model real-world objects and their relationships,
making it easier to understand and work with complex
systems.

Another advantage of OOP is that it supports


encapsulation and abstraction, which helps to minimize
the impact of changes to one part of the code on other
parts of the code. This makes it easier to maintain and
update the code as requirements evolve.

24 | Heemali Chaudhari
What are the main features of OOPs?
The main features of Object-Oriented Programming (OOP) are:

Encapsulation: This is the process of wrapping data and


behavior within a single unit or object, which helps to
protect the data and ensure that it is only accessible through
an object's methods.
Abstraction: This is the process of hiding the underlying
complexity of an object and exposing only the essential
features, making it easier to understand and use.
Inheritance: This is the mechanism by which a new class can
be created by inheriting properties and behaviors from an
existing class, making it possible to reuse and extend existing
code.
Polymorphism: This is the ability of an object to take on
multiple forms, depending on the context in which it is used.
This allows for more flexible and dynamic code that can be
adapted to different situations.
Classes: A class is a blueprint for creating objects, which
defines the properties and behaviors that the objects created
from that class will have.

These features allow OOP to provide a way to organize,


structure, and manage complex systems, making it easier to
build and maintain large, scalable applications.

25 | Heemali Chaudhari
Explain Inheritance in Python with an example.
Inheritance is a key concept in Object-Oriented
Programming that allows you to create a new class based on
an existing class, inheriting all its properties and behaviors.
This makes it possible to reuse and extend existing code,
reducing duplicated code and making it easier to maintain
the code over time.

What is monkey patching in Python?


Monkey patching is a technique in which you modify or
extend the behavior of a class or module at runtime. It is
often used to add new features or to modify existing features
in a way that does not require changing the original code.
This can be useful in situations where you don't have control
over the source code, or where you want to add or change
behavior temporarily or for specific use cases.

Does python support multiple inheritance?


Yes, Python supports multiple inheritance, which means that
a class can inherit from multiple base classes. This allows you
to create classes that inherit properties and behaviors from
multiple sources, making it easier to reuse and combine
existing code.

26 | Heemali Chaudhari
What is Polymorphism in Python?
Polymorphism is a key concept in Object-Oriented
Programming that allows objects of different classes to be
treated as objects of a common type. This makes it possible
to write code that can work with objects of different types
in a generic way, without having to know the specific type
of the object at runtime.

What is static polymorphism?


Static polymorphism, also known as early binding or
compile-time polymorphism, refers to the behavior of an
object in which the type of the object and the method to be
called are determined at compile time. This means that the
exact method to be called is known before the program is
executed.

What is dynamic polymorphism?


Dynamic polymorphism, also known as late binding or
run-time polymorphism, refers to the behavior of an
object in which the type of the object and the method to be
called are determined at run time. This means that the
exact method to be called is not known until the program
is executed.

27 | Heemali Chaudhari
Differentiate between overloading and overriding.
Method overloading is a feature of object-oriented
programming that allows a class to have multiple methods
with the same name but different parameters. This allows
the class to perform different actions based on the
arguments passed to the method. For example, a class
might have two methods with the same name but one takes
an integer argument and the other takes a string
argument. When the method is called, the correct
implementation will be selected based on the type of
argument passed to it.

Method overriding, on the other hand, is the ability of a


subclass to provide a different implementation of a method
that is already defined in its superclass. The purpose of
overriding is to change the behavior of a method in the
subclass to provide a more specific implementation.

Define encapsulation in Python?


Encapsulation is a fundamental principle of object-
oriented programming (OOP) that involves bundling data
and methods that operate on that data within a single unit
or object. In Python, this is achieved by defining class
methods and attributes.

28 | Heemali Chaudhari
What are ‘access specifiers’?
Access specifiers are keywords in object-oriented
programming (OOP) that define the level of access to the
members (attributes and methods) of a class. The access level
of a member determines who can access and modify it within
the program.

Public: Members declared as public can be accessed from


anywhere within the program.

Private: Members declared as private can only be accessed


within the same class. They are prefixed with two
underscores in Python (e.g. __private_member).

Protected: Members declared as protected can only be


accessed within the same class and its subclasses. They are
prefixed with a single underscore in Python (e.g.
_protected_member).

Access specifiers help to enforce encapsulation by controlling


the visibility and accessibility of class members. By limiting
the visibility of certain members, the implementation details
of a class can be kept hidden from other parts of the code,
making it easier to maintain and modify the code in the
future.

29 | Heemali Chaudhari
What is the difference between multiple and multilevel
inheritance?
Multiple inheritance is when a class inherits attributes and
methods from multiple parent classes. It allows a class to
inherit the characteristics of more than one parent class.
For example, if a class Child inherits from two classes
Parent1 and Parent2, it will have access to the attributes
and methods of both Parent1 and Parent2.

Multilevel inheritance is when a class inherits from a


parent class which in turn inherits from another parent
class. It creates a hierarchy of inheritance where a class
can inherit from a parent class, which in turn inherits
from another parent class, and so on. For example, if a
class Grandchild inherits from a class Child which in turn
inherits from a class Parent, then Grandchild will have
access to the attributes and methods of both Child and
Parent.

30 | Heemali Chaudhari
What are the limitations of inheritance?
Inheritance is a powerful feature in object-oriented
programming (OOP) that allows classes to inherit
attributes and methods from parent classes. However,
it also has some limitations:
Complexity: Inheritance can increase the complexity
of the code, making it harder to understand and
maintain. When classes inherit from multiple parent
classes, the relationships between classes can become
difficult to understand, especially when inheritance
hierarchies become deep and complex.
Overuse: Inheritance should be used carefully and
only when it is the most appropriate solution. Overuse
of inheritance can lead to complex, inflexible, and
hard-to-maintain code.

What is data abstraction?


Data abstraction is a technique used in object-oriented
programming (OOP) to separate the implementation
details of a class from its interface. It refers to the act of
exposing only the necessary information about an object to
the outside world, while hiding its internal details.

31 | Heemali Chaudhari
What are virtual functions?
In Python, virtual functions or "duck typing" is a feature of
the dynamic typing system that allows a method or function
to be called on objects of different types, as long as they
implement the required method or interface. This is done
based on the type of the object at runtime rather than the
type declared in the code.

What is a constructor? Types


A constructor is a special method in object-oriented
programming that is automatically called when an object is
created from a class. The purpose of the constructor is to
initialize the attributes of the newly created object.

There are two types of constructors in Python:


Default Constructor: If a class does not have an __init__
method defined, Python provides a default constructor that
does not take any arguments and does not initialize any
attributes.

Parameterized Constructor: If a class defines an __init__


method, it is a parameterized constructor, and it can take any
number of arguments and initialize the attributes of the
newly created object accordingly.

32 | Heemali Chaudhari
What is a destructor?
In Python, a destructor is a special method that is
automatically called when an object is about to be
destroyed. The purpose of a destructor is to perform any
necessary clean-up operations, such as freeing resources or
closing files, before the object is destroyed.

Differentiate between a class and a method.


A class in Python is a blueprint for creating objects, which
defines a set of attributes and behaviors that the objects
created from the class will have, while a method is a
function that is associated with a class and operates on
objects created from that class.

What is an exception?
An exception in Python is an event that occurs during the
execution of a program that disrupts the normal flow of
the program's instructions. Exceptions are raised when a
runtime error occurs, such as dividing by zero or trying to
access an index that is out of range. When an exception is
raised, the normal flow of the program is interrupted and
the program execution is transferred to the nearest
exception handling code.

33 | Heemali Chaudhari
What is a map function in Python?
The map function in Python is a built-in function that
applies a function to each item of an iterable (such as a list,
tuple, or string) and returns a map object with the results.
The map object can be converted to other Python objects
(such as a list) using the list or tuple constructor.

Do we need to declare variables with data types in Python?


No, in Python, you do not have to explicitly declare
variables with data types. Python is dynamically typed,
which means that the type of a variable is determined
automatically based on the value assigned to it. This allows
for greater flexibility and makes it easier to write and
maintain code, as you don't have to specify the type of
each variable upfront. However, it can also lead to
potential type errors if you're not careful, as the type of a
variable can change during the execution of a program.

34 | Heemali Chaudhari
Is Python fully object oriented?
Yes, Python is considered a fully object-oriented
programming language. This means that almost
everything in Python is an object, including numbers,
strings, functions, and even modules.

In Python, classes are used to define custom objects, and


objects can have attributes (also known as instance
variables) and methods. Python supports inheritance,
polymorphism, and encapsulation, which are the three
main principles of object-oriented programming.

What is the difference between append() and extend()


methods?
The append() method adds an element to the end of a list
as a single item, while the extend() method adds all the
elements of an iterable to the end of a list.

How is Multithreading achieved in Python?


Multithreading in Python is achieved using the threading
module. The threading module provides the Thread class,
which can be used to create and run multiple threads in
parallel. Each thread runs in parallel with the main thread
and can perform independent tasks.

35 | Heemali Chaudhari
What is functional programming? Does Python follow a
functional programming style?
Functional programming is a programming paradigm that
emphasizes the use of pure functions, immutability, and
the avoidance of side effects. In functional programming,
functions are first-class citizens and are treated as building
blocks that can be combined to create complex programs.

Functional programming has several key features,


including:

Pure functions: Functions that have no side effects,


meaning they don't modify the state of the program or
interact with the outside world.
Immutable data structures: Data structures that
cannot be modified after they are created, which
makes it easier to reason about the behavior of the
program.
Higher-order functions: Functions that take other
functions as arguments or return functions as results.

Python is not a purely functional programming language,


but it does have some functional programming features
and supports functional programming techniques.

36 | Heemali Chaudhari
What is the difference between / and // operator in Python?
In Python, the / operator performs floating-point division,
while the // operator performs integer division, also known as
floor division.

Floating-point division returns a floating-point number that


represents the exact division result, including any fractional
part. Floor division, on the other hand, rounds down the
result to the nearest integer and returns an integer value.

What is pandas?
Pandas is an open-source data analysis and data
manipulation library for Python. It provides data structures
for efficiently storing large amounts of structured data, as
well as tools for working with that data in a convenient and
expressive way.

What are dataframes?


Dataframes are a key component of pandas and are used for
a wide variety of data analysis tasks, such as cleaning and
transforming data, aggregating and summarizing data, and
merging and joining data from multiple sources. They are
optimized for performance and memory usage, and provide a
convenient and expressive interface for working with
structured data.

37 | Heemali Chaudhari
How do you identify missing values and deal with missing values
in Dataframe?
Identifying missing values in a pandas DataFrame can be done
using the isna() or isnull() methods, which return a DataFrame
of the same shape as the original DataFrame with True values in
cells where missing (null) values are detected.

What is regression?
Regression is a statistical method for modeling the relationship
between a dependent variable and one or more independent
variables. The goal of regression is to find a mathematical
equation that best describes the relationship between the
variables, allowing us to make predictions about the dependent
variable based on values of the independent variables.

What is classification?
Classification is a machine learning technique used to predict a
categorical label (or class) based on a set of input features. In
other words, it's a way of sorting items into one of several
predefined categories based on their characteristics.

Classification algorithms can be supervised, meaning that they


learn from labeled training data, or unsupervised, meaning that
they learn from unlabeled data. There are several popular
classification algorithms, including decision trees, random
forests, support vector machines, and neural networks.

38 | Heemali Chaudhari
Give me a list of Python Libraries and their uses?

NumPy - used for numerical computing and scientific


computing.
Pandas - used for data analysis and manipulation.
Matplotlib - used for data visualization.
Seaborn - used for data visualization based on
Matplotlib.
Scikit-learn - used for machine learning.
TensorFlow - used for deep learning and machine
learning.
Keras - used for building and training deep learning
models.
PyTorch - used for deep learning and machine
learning.
NLTK - used for natural language processing.
Scrapy - used for web scraping.
Beautiful Soup - used for web scraping and data
extraction from HTML and XML files.
Flask - used for building web applications.
Django - used for building full-stack web applications.
Requests - used for sending HTTP requests.

39 | Heemali Chaudhari
What is the use of Matplotlib in data visualization?
Matplotlib is a data visualization library in Python that
provides a collection of functions and methods to create
static, animated, and interactive visualizations. It provides a
high-level interface for drawing attractive and informative
statistical graphics.

Some of the use cases of Matplotlib in data visualization are:


Plotting line plots, scatter plots, bar plots, histograms,
and other types of plots to visualize the relationship
between variables.
Plotting pie charts, box plots, and violin plots to visualize
the distribution of data.
Creating heatmaps, contour plots, and 3D plots to
visualize the density of data in a 2D or 3D space.
Adding annotations, labels, legends, and other elements
to plots to provide additional information.
Saving and exporting plots in different formats, such as
PNG, PDF, and SVG.

Matplotlib is a flexible library that can be used for a wide


range of data visualization tasks. It can be used for
exploratory data analysis, for creating visualizations for
reports, and for creating visualizations for data-driven
presentations.

40 | Heemali Chaudhari
What is Plotly and when would you use it for data
visualization?
Plotly is an open-source data visualization library for
Python, R, and JavaScript. It provides a high-level
interface for creating interactive and animated
visualizations in a web browser. Unlike Matplotlib, which
generates static visualizations, Plotly creates interactive
visualizations that can be interacted with and explored by
the user.

You would use Plotly for data visualization in the


following scenarios:
When you want to create interactive visualizations that
allow the user to zoom, pan, hover, and explore the
data.
When you want to create visualizations that can be
embedded in web pages or shared online.
When you want to create visualizations that can be
used in dashboard applications or in data-driven
presentations.
When you want to create animated visualizations to
show changes in data over time.
When you want to create 3D visualizations and
visualize data in a 3D space.

41 | Heemali Chaudhari
What is the use of the Scikit-learn library in machine
learning?
Scikit-learn is a machine learning library for Python that
provides simple and efficient tools for data mining and
data analysis. It contains a variety of algorithms for
classification, regression, clustering, dimensionality
reduction, and model selection, among others. The library
provides a unified interface to these algorithms, making it
easy to switch between different algorithms and to
compare the results.

What is the role of the Keras library in deep learning?


Keras is a high-level deep learning library for Python that
provides a simple and user-friendly interface for building
and training deep learning models. It supports a variety of
neural network architectures, including feedforward
networks, convolutional networks, recurrent networks,
and autoencoders. The library is designed to be fast and
efficient, allowing you to quickly build and experiment
with different deep learning models.

42 | Heemali Chaudhari
Can you explain how to perform feature selection using
the scikit-learn library?
Feature selection is the process of selecting a subset of
relevant features from a larger set of features for use in a
machine learning model. In scikit-learn, there are several
methods for feature selection, including univariate feature
selection, recursive feature elimination, and lasso
regularization. To perform feature selection, you can use
the SelectKBest or SelectFromModel classes, which can be
applied to the data before training a machine learning
model.

What is Seaborn and how does it differ from Matplotlib?


Seaborn is a data visualization library in Python that is
built on top of Matplotlib and provides a higher-level
interface for creating statistical graphics. It provides more
sophisticated default styles and color palettes than
Matplotlib, and also provides more advanced visualization
techniques, such as violin plots, box plots, and heatmaps.
Additionally, Seaborn provides an interface for plotting
statistical models, making it easier to create plots that
visualize the results of regression and other statistical
models.

43 | Heemali Chaudhari
Can you explain how to perform sentiment analysis with the
NLTK library?
Sentiment analysis is the process of determining the sentiment or
emotion expressed in a piece of text, such as a tweet or a
customer review. In NLTK, sentiment analysis can be performed
using various techniques, including bag-of-words models, n-
gram models, and deep learning models. To perform sentiment
analysis, you can start by preprocessing the text data, such as
removing stop words and stemming the words. Then, you can
use the TextBlob or Vader SentimentIntensityAnalyzer libraries
to classify the sentiment of each text.

What is the role of the TensorFlow library in deep learning and


artificial intelligence?
TensorFlow is an open-source software library for machine
learning and deep learning, developed by Google. It provides a
flexible and efficient platform for building, training, and
deploying machine learning models, including deep neural
networks. TensorFlow allows you to build and experiment with
different deep learning models, and provides tools for
visualization and debugging during the model development
process. Additionally, TensorFlow provides a large number of
pre-trained models for a variety of tasks, such as image
classification, natural language processing, and speech
recognition.

44 | Heemali Chaudhari
What is the difference between static and dynamic typing
in Python, and how does it affect library usage?
Static typing refers to the practice of declaring the data
type of a variable before its use. This means that the type
of a variable is determined at compile-time and cannot
change during runtime.

Dynamic typing, on the other hand, allows the type of a


variable to change during runtime. In Python, the type of
a variable is determined by the value that is assigned to it.
For example, you can assign an integer to a variable, and
then later assign a string to that same variable.

Static typing is used in languages such as Java, while


dynamic typing is used in languages such as Python. In
general, dynamic typing provides greater flexibility and
can simplify the development process, while static typing
provides better performance and makes it easier to catch
type-related errors.

45 | Heemali Chaudhari
Found this helpful?

Follow me for more

such resources : )

You might also like