Important_Python_Questions_FULL
Important_Python_Questions_FULL
Summer 2025
Most Important Questions with Answers
Example:
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
Example:
g = 10
def func():
l=5
print("Local:", l)
print("Global:", g)
func()
While loop:
i=0
while i < 3:
print("While loop:", i)
i += 1
Example:
d = {"name": "John", "age": 22}
d["city"] = "Mumbai"
d.pop("age")
print(d)
5. Explain types of function arguments in Python.
- Positional Arguments
- Default Arguments
- Keyword Arguments
- Variable Length Arguments
Example:
def func(a, b=2, *args, **kwargs):
print(a, b, args, kwargs)
func(1, 3, 4, 5, name="John")
Example:
try:
x=5/0
except ZeroDivisionError:
print("Cannot divide by zero")
Example:
import math
print(math.sqrt(16))
class Student:
def __init__(self, name):
self.name = name
def show(self):
print("Name:", self.name)
s = Student("Alice")
s.show()
while True:
print("1.Add 2.Sub 3.Mul 4.Div 5.Exit")
ch = int(input("Choice: "))
if ch == 5: break
x = int(input("x: "))
y = int(input("y: "))
if ch == 1: print(add(x, y))
elif ch == 2: print(sub(x, y))
elif ch == 3: print(mul(x, y))
elif ch == 4: print(div(x, y))
def fact(n):
if n == 1:
return 1
return n * fact(n-1)
print(fact(5))
11. Write a program to accept N numbers and find the largest using list.
# Write
f = open("test.txt", "w")
f.write("Python file example")
f.close()
# Read
f = open("test.txt", "r")
print(f.read())
f.close()
13. Write a class Student with methods to accept and display data.
class Student:
def __init__(self):
self.name = input("Enter name: ")
self.roll = input("Enter roll: ")
def display(self):
print(self.name, self.roll)
s = Student()
s.display()
class Person:
def __init__(self, name):
self.name = name
class Student(Person):
def display(self):
print("Student:", self.name)
s = Student("John")
s.display()
try:
x = int(input("Enter a number: "))
print(10 / x)
except ZeroDivisionError:
print("Division by zero is not allowed")