← Back
Question 21 Interview Prep

What is exception handling in Python?

Exception handling is a process used to handle runtime errors without stopping the execution of the program. In Python, exceptions are commonly handled using try, except, finally, and else blocks.

Example:

try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")

Exception handling helps make applications more stable and user-friendly.

Question 22 Interview Prep

What is the difference between syntax errors and runtime errors?

A syntax error occurs when the code violates Python's grammar rules, while a runtime error occurs during program execution.

Example of syntax error:

if True
print("Hello")

Example of runtime error:

print(10 / 0)

Syntax errors prevent the program from starting, whereas runtime errors occur after execution begins.

Question 23 Interview Prep

What is None in Python?

None is a special constant in Python that represents the absence of a value or a null value.

Example:

value = None

It is commonly used as a default value or placeholder.

Question 24 Interview Prep

What is a module in Python?

A module is a Python file that contains functions, variables, or classes which can be reused in other programs.

Example:

import math

print(math.sqrt(16))

Modules help organize code and improve reusability.

Question 25 Interview Prep

What is a package in Python?

A package is a collection of multiple Python modules organized inside a directory. It helps structure large applications efficiently.

In simple terms:

Module → single Python file
Package → collection of modules

Question 26 Interview Prep

What is pip in Python?

pip is Python's package manager used to install and manage external libraries and packages.

Example:

pip install requests

It allows developers to easily use third-party tools and frameworks.

Question 27 Interview Prep

What is Object-Oriented Programming (OOP)?

Object-Oriented Programming is a programming approach that organizes code using classes and objects. It helps improve code reusability, scalability, and maintainability.

The four main pillars of OOP are:

Encapsulation
Inheritance
Polymorphism
Abstraction

OOP is widely used in real-world application development.

Question 28 Interview Prep

What is a class in Python?

A class is a blueprint or template used to create objects. It defines the properties and behaviors that objects will have.

Example:

class Car:
pass

Classes help organize related data and functionality together.

Question 29 Interview Prep

What is an object in Python?

An object is an instance of a class. It represents a real-world entity and can access the variables and methods defined inside the class.

Example:

class Car:
pass

car1 = Car()

Here, car1 is an object of the Car class.

Question 30 Interview Prep

What is a constructor in Python?

A constructor is a special method that gets called automatically when an object is created. In Python, the constructor method is written as __init__().

It is mainly used to initialize object attributes.

Example:

class Student:

def __init__(self, name):
self.name = name

student1 = Student("Rahul")

Constructors help assign initial values to objects.