BCA-75T-303
Python Programming (Theory)
Assignment
Q1. Explain Mutable and Immutable Data Types in Python with example.
In Python, data types are classified as mutable and immutable based on whether their values can be
changed after creation. Mutable Data Types: Mutable objects can be modified after creation. Examples
include List, Dictionary, and Set. Example: list1 = [1, 2, 3] list1[0] = 10 Immutable Data Types:
Immutable objects cannot be modified after creation. Examples include Integer, Float, String, and
Tuple. Example: x = 10 x = 20 (creates a new object instead of modifying the old one)
Q2. Explain Conditional Statements and Looping Statements in Python with example.
Conditional statements are used to make decisions in Python. Types: • if • if-else • if-elif-else Example:
if age >= 18: print("Eligible to vote") Looping statements are used to execute a block of code repeatedly.
Types: • for loop • while loop Example: for i in range(5): print(i)
Q3. Explain Class and Object in Python with example.
A class is a blueprint for creating objects. An object is an instance of a class. Example: class Student:
def __init__(self, name): [Link] = name s1 = Student("Rahul") print([Link])
Q4. Explain Set in Python: introduction, accessing, built-in methods and operations.
A Set is an unordered collection of unique elements. Built-in Methods: add(), update(), remove(),
discard(), clear(), copy() Operations: Union, Intersection, Difference Example: A = {1,2,3} B = {3,4,5}
print([Link](B))
Q5. Explain Dictionary in Python.
A Dictionary stores data in key-value pairs. Features: • Fast lookup • Mutable • Allows nested
dictionaries Example: student = {"name":"Amit", "age":20} print(student["name"])
Q6. Explain Regular Expression in Python with example.
Regular Expressions are used for pattern matching in strings. Example: import re text = "Python123"
result = [Link]("\d+", text) print([Link]())
Q7. Explain Exception Handling in Python with example.
Exception handling is used to handle runtime errors. Keywords: try, except, finally Example: try: x =
10/0 except ZeroDivisionError: print("Cannot divide by zero")
Q8. Explain Multithreading and its types in Python with example.
Multithreading allows concurrent execution of threads. Types: • Single-threading • Multi-threading
Example: import threading def task(): print("Thread running") t = [Link](target=task) [Link]()