2 marks questions
1. Why Python is an interpreted language?
Python is called an interpreted language because the Python interpreter executes the code line by
line at runtime without converting it into machine code beforehand.
2. Explain membership operators.
Membership operators are used to check whether a value is present in a sequence.
in → returns True if value exists
not in → returns True if value does not exist
3. What is a tuple? Give an example.
A tuple is an ordered, immutable collection of elements enclosed in parentheses.
Example:
tuple1 = (10, 20, 30)
4. Define encapsulation and inheritance.
Encapsulation: Wrapping data and methods into a single unit (class).
Inheritance: A process where one class acquires properties of another class.
5. What is constructor method in Python?
A constructor is a special method named __init__() which is automatically called when an
object of a class is created to initialize data members.
6. What is a file? Mention the types of files.
A file is a collection of data stored permanently on secondary storage.
Types of files:
Text files
Binary files
7. Why Python is called a Dynamically Typed Language?
Python is dynamically typed because variable types are decided at runtime, and no need to
declare the data type explicitly.
8. Explain Concatenation and Repetition Operators.
Concatenation (+) joins two sequences.
Repetition (*) repeats a sequence multiple times.
Example:
"Hi" + "Hello" , "Hi" * 3
9. What is List? Give an example.
A list is an ordered, mutable collection of elements enclosed in square brackets.
Example:
list1 = [1, 2, 3, 4]
10. Define Local Variables and Global Variables.
Local variable: Declared inside a function and accessible only within it.
Global variable: Declared outside a function and accessible throughout the program.
11. Tuples are Immutable. Explain with an example.
Tuples are immutable because their elements cannot be modified after creation.
Example:
tuple1 = (1, 2, 3)
tuple1[0] = 10 → Error
12. Difference between text file and binary file with example.
Text file: Stores data in readable form.
Example: [Link]
Binary file: Stores data in binary format.
Example: [Link]
13. What is Python? List the execution modes in Python.
Python is a high-level, interpreted, object-oriented programming language.
Execution modes:
Interactive mode
Script mode
14. Define function. Name the types of functions in Python.
A function is a block of reusable code that performs a specific task.
Types of functions:
Built-in functions
User-defined functions
15. What is indexing and negative indexing in a string?
Indexing: Accessing characters using positive index starting from 0.
Negative indexing: Accessing characters from the end using negative numbers.
16. Give difference between list and string.
List: Mutable collection, elements can be changed.
String: Immutable sequence of characters.
17. What is pickling and unpickling?
Pickling: Converting Python object into byte stream.
Unpickling: Converting byte stream back into Python object.
18. Define abstraction and inheritance.
Abstraction: Hiding internal details and showing only essential features.
Inheritance: A class acquiring properties and methods of another class.
6 marks questions
19. Explain the features of Python. (6 Marks)
Python has several powerful features which make it a popular programming language:
1. Simple and Easy to Learn – Python uses readable, English-like syntax.
2. Interpreted Language – Code is executed line by line, making debugging easy.
3. Dynamically Typed – Data types are decided at runtime.
4. Object-Oriented – Supports classes, objects, inheritance, polymorphism.
5. Platform Independent – Same program runs on Windows, Linux, and macOS.
6. Extensive Standard Library – Provides built-in modules for file handling, math,
networking, etc.
20. String slicing in Python with examples. (6 Marks)
String slicing extracts a part of a string using index values.
Syntax:
string[start : end : step]
Points:
1. Index starts from 0.
2. End index is excluded.
3. Negative indexing is allowed.
4. Step value controls skipping characters.
5. Original string remains unchanged.
6. Useful for substring operations.
Example:
s = "PythonProgramming"
print(s[0:6])
print(s[-11:-1])
21. Difference between List and Tuple. (6 Marks)
Feature List Tuple
Mutability Mutable Immutable
Brackets [ ] ( )
Speed Slower Faster
Memory More Less
Methods Many Limited
Usage Dynamic data Fixed data
Example code included in exam answer
22. Creating classes and objects in Python. (6 Marks)
A class defines properties and behavior of objects.
Steps:
1. Define class using class keyword.
2. Use constructor __init__() to initialize variables.
3. Define methods inside class.
4. Create object using class name.
5. Access methods using object.
6. Reusability and modularity achieved.
Example:
class Student:
def __init__(self, name, age):
[Link] = name
[Link] = age
def show(self):
print([Link], [Link])
s = Student("Jyothi", 20)
[Link]()
23. File modes in Python. (6 Marks)
File modes specify how a file is accessed.
1. r – Read mode (default).
2. w – Write mode (overwrites file).
3. a – Append mode.
4. r+ – Read and write.
5. b – Binary mode.
6. t – Text mode.
Example:
file = open("[Link]", "a")
24. Data Visualization & Python Libraries. (6 Marks)
Data visualization is graphical representation of data.
Importance:
1. Easy understanding of data.
2. Detect trends and patterns.
3. Used in business analytics.
4. Supports decision making.
5. Reduces data complexity.
6. Improves communication.
Libraries:
Matplotlib
Seaborn
Plotly
Pandas
Bokeh
25. break and continue statements. (6 Marks)
1. Used inside loops.
2. break exits the loop completely.
3. continue skips current iteration.
4. Improves control flow.
5. Saves execution time.
6. Avoids unnecessary iterations.
Example included
26. Python Built-in Data Types. (6 Marks)
1. Numeric – int, float, complex.
2. Sequence – list, tuple, string.
3. Mapping – dictionary.
4. Set – set, frozenset.
5. Boolean – True, False.
6. None type – None.
27. File writing, reading & appending. (6 Marks)
Steps:
1. Open file using open().
2. Write using write().
3. Append using append mode.
4. Read using read().
5. Close file.
6. Difference explained.
Key difference:
Write → overwrites.
Append → adds data.
28. Types of inheritance in Python. (6 Marks)
1. Single
2. Multiple
3. Multilevel
4. Hierarchical
5. Hybrid
6. Code reusability achieved
Simple diagram explanation included
29. Matplotlib & its features. (6 Marks)
Matplotlib is a visualization library.
Features:
1. Supports various charts.
2. Easy to use.
3. Customizable plots.
4. Works with NumPy.
5. Interactive graphs.
6. Used in data science.
30. Six tuple built-in functions. (6 Marks)
1. len()
2. max()
3. min()
4. sum()
5. count()
6. index()
32. What does it mean that strings are immutable? Explain
five string methods.
Strings are immutable, meaning they cannot be changed after creation.
Example:
s = "Hello"
# s[0] = 'h' → Error
String Methods:
upper()
lower()
strip()
replace()
split()
33. Explain len(), any(), all() and sorted() on dictionary.
len() → Number of keys
any() → True if any key is True
all() → True if all keys are True
sorted() → Returns sorted keys
Example:
d = {1:10, 2:20}
print(len(d))
print(sorted(d))
34. Write differences between tuple and dictionary.
Tuple Dictionary
Ordered Unordered
Indexed Key-value
Immutable Mutable
Uses ( ) Uses { }
35. What is data visualization? Explain role of Matplotlib.
Data visualization converts data into charts and graphs.
Role of Matplotlib:
Creates visual plots
Helps analyze data patterns
Supports many chart types
Easy integration with data libraries
36. What is frozen set? Explain set methods.
A frozenset is an immutable version of a set.
Set Methods:
difference() – Returns difference
difference_update() – Updates original set
intersection() – Common elements
intersection_update() – Updates with common elements
Example:
a = {1,2,3}
b = {2,3,4}
print([Link](b))
10 marks question