Q1. What is Python? Explain its main features.
Python is a high-level, interpreted programming language.
Features:
• Easy to read and write
• Platform independent
• Supports object-oriented programming
Q2. Define variables and its types.
A variable is a name used to store data in memory.
Types:
• Local variable
• Global variable
Q3. What are local and global variables?
Local variables are declared inside a function and used only there.
Global variables are declared outside functions and can be used anywhere.
Q4. Define operator with its types.
Operators perform operations on values.
Types:
• Arithmetic
• Relational
• Logical
• Assignment
Q5. Define data types in Python.
Data types specify the type of data stored in a variable.
Examples:
• int
• float
• string
• list
Q6. What are conditional statements in Python?
Conditional statements execute code based on conditions.
Examples:
• if
• if–else
• elif
Q7. Explain loop constructs in Python.
Loops are used for repeated execution of code.
Types:
• for loop
• while loop
Q8. What is a string in Python? Explain its methods.
A string is a sequence of characters enclosed in quotes.
Methods:
• upper()
• lower()
• split()
Q9. What is string manipulation and slicing?
String manipulation means modifying strings.
Slicing extracts a part of a string using index values.
Q10. What is a function? Explain its types.
A function is a block of reusable code.
Types:
• Built-in functions
• User-defined functions
Q11. Explain function parameters and arguments.
Parameters are variables in function definition.
Arguments are values passed during function call.
Q12. Difference between parameters and arguments.
Parameters receive values.
Arguments send values.
Q13. Explain types of arguments.
Types:
• Positional
• Keyword
• Default
Q14. Difference between function definition and calling.
Definition creates a function.
Calling executes the function.
Q15. Define list with example.
A list is an ordered, mutable collection.
Example: a = [1, 2, 3]
Q16. Define tuple with example.
A tuple is an ordered, immutable collection.
Example: t = (1, 2, 3)
Q17. Define dictionary with example.
A dictionary stores key-value pairs.
Example: d = {"a":1, "b":2}
Q18. Define set with example.
A set is an unordered collection of unique elements.
Example: s = {1, 2, 3}
Q19. Difference between list, tuple and dictionary.
• List: ordered, mutable
• Tuple: ordered, immutable
• Dictionary: key-value pairs
Q20. What is a module? Explain types with example.
A module is a file containing Python code.
Types:
• Built-in (math)
• User-defined
Q21. Difference between module and package.
Module: single file
Package: collection of modules
Q22. What is recursion? Give example.
Recursion is a function calling itself.
Example: factorial calculation
Q23. Explain file handling and its importance.
File handling is used to read/write files.
It helps store data permanently.
Q24. Common file operations.
• open
• read
• write
• close
Q25. Types of files in Python.
• Text files ([Link])
• Binary files ([Link])
Q26. Difference between text and binary files.
Text files store readable data.
Binary files store non-readable data.
Q27. Explain file I/O operations.
Files are opened using open()
Data read/write using read() and write()
Closed using close()
Q28. Program to create, rename and delete file.
import os
open("[Link]","w")
[Link]("[Link]","[Link]")
[Link]("[Link]")
Q29. Explain file pointer with example.
File pointer shows current position in file.
Example: [Link]()
Q30. Explain different file modes.
• r – read
• w – write
• a – append
• rb – read binary
Q31. Define exception and its types.
Exception is an error during execution.
Types:
• ZeroDivisionError
• ValueError
Q32. Difference between syntax error and runtime error.
Syntax error: occurs due to wrong syntax.
Runtime error: occurs during execution.
Q33. What is exception handling? Why needed?
Exception handling manages runtime errors.
It prevents program crash.
Q34. Explain try, except, else and finally.
try: risky code
except: handle error
else: runs if no error
finally: always executes
Q35. Why is Python popular for data analysis?
• Simple syntax
• Powerful libraries
• Fast data processing
Q36. Role of NumPy, Pandas, Matplotlib.
• NumPy – numerical operations
• Pandas – data handling
• Matplotlib – data visualization
Q37. Python programs:
import pandas as pd
s = [Link]([1,2,3])
df = [Link]({"A":[1,2],"B":[3,4]})
import numpy as np
a = [1,2,3]
print([Link](a))
Q38. Python libraries with examples.
• NumPy – numerical computing
• Pandas – data analysis
• Matplotlib – plotting