UNIT I – Introduction to Python
2 Marks Answers
1. Python is a high-level, interpreted, and general-purpose programming language that emphasizes readability and
simplicity.
2. A variable is a named memory location used to store data values during program execution.
3. Boolean values represent logical values: True and False.
4. A string is a sequence of characters enclosed within single, double, or triple quotes.
5. Syntax error occurs due to incorrect syntax, and runtime error occurs while executing the program.
5 Marks Answers
Variables and Memory Model: Variables store values in memory. Python dynamically allocates memory, and
variables act as references to objects.
Types of Errors: Syntax errors violate grammar rules. Runtime errors occur during execution. Logical errors give
incorrect output without stopping execution.
Boolean Expressions: Expressions that evaluate to True or False using relational and logical operators such as >,
<, ==, and, or, not.
If–Else Statements: Used for decision making. Nested if statements allow multiple conditions to be tested inside
one another.
10 Marks Answers
Functions in Python: Functions are reusable blocks of code defined using the def keyword. They help reduce code
repetition and improve readability. Functions may or may not return values. Built-in functions include print(), len(),
type(). User-defined functions are created by programmers. Function calls create a stack frame in memory and
execution returns after completion.
Strings and Text Processing: Strings can be created using quotes. Special characters like \n and \t format output.
Multiline strings use triple quotes. Input is taken using input() and output using print().
UNIT II – Modular Programming and Lists
2 Marks Answers
1. A module is a file containing Python definitions and statements.
2. A class is a blueprint for creating objects.
3. A method is a function defined inside a class.
4. List slicing extracts a portion of a list using index range.
5. Aliasing occurs when two variables point to the same list object.
5 Marks Answers
Modules: Modules are imported using import or from keyword. Example: import math.
String Methods: Common methods include upper(), lower(), split(), replace().
List Operations: Lists support insertion, deletion, updating, slicing, and iteration.
Aliasing: Changes made through one reference affect the other reference.
10 Marks Answers
Lists in Python: Lists are mutable, ordered collections. They allow duplicate values. Operations include indexing,
slicing, appending, deleting, sorting, and nesting. A list of lists is used to represent matrices and tables.
Object-Oriented Programming: OOP is based on class and object concepts. It supports encapsulation,
inheritance, polymorphism, and abstraction for better program structure.
UNIT III – Loops and File Handling
2 Marks Answers
1. A loop is used to execute a block of code repeatedly.
2. for loop iterates over sequences, while loop executes until condition becomes false.
3. break terminates the loop immediately.
4. A file is a collection of data stored permanently on secondary storage.
5. File modes include read (r), write (w), and append (a).
5 Marks Answers
For Loop: Used to iterate over a sequence such as list or string using range().
While Loop: Executes repeatedly as long as condition remains True.
Break and Continue: break exits loop, continue skips current iteration.
File Modes: r – read, w – write, a – append.
10 Marks Answers
Looping Concepts: Python supports for and while loops. Nested loops allow loops inside loops. break and
continue control loop flow.
File Handling: Files are opened using open(). Data is read using read(), readline(), or readlines(). Writing is done
using write(). Files must be closed to free resources.
UNIT IV – Collections and GUI Programming
2 Marks Answers
1. A tuple is an immutable collection of elements.
2. A dictionary stores data in key-value pairs.
3. A set stores unordered and unique elements.
4. GUI stands for Graphical User Interface.
5. An instance is an object created from a class.
5 Marks Answers
Dictionaries: Used to store key-value pairs. Example: {'id':1}.
Collection Comparison: Lists are ordered, tuples immutable, sets unordered.
Special Methods: __init__() initializes object data.
MVC Architecture: Separates program into Model, View, and Controller.
10 Marks Answers
Collection Types: Tuples, sets, and dictionaries are used based on mutability and data access needs. Each has
specific operations and use cases.
GUI Programming: GUI uses widgets such as buttons, labels, and text boxes. MVC architecture avoids complexity
and improves maintainability.