Unit I: Introduction to Python and Control Flow Statements
Q1: What are the features of Python?
A: Python is simple, easy to learn, free and open-source, portable, interpreted,
dynamically typed, and supports object-oriented programming.
Q2: Name any two Python IDEs.
A: PyCharm, IDLE.
Q3: What is indentation in Python?
A: Indentation is the space at the beginning of a code line. It is used to define blocks of
code, especially in loops, functions, and conditionals.
Q4: What is the use of input() and print() in Python?
A: input() is used to take input from the user, and print() is used to display output.
Q5: What are the different types of operators in Python?
A: Arithmetic, Relational, Assignment, Logical, Bitwise, Membership, and Identity
operators.
Q6: Name any two loop control statements in Python.
A: break, continue.
Q7: Who developed Python and when?
A: Python was developed by Guido van Rossum in 1991.
Q8: What are keywords in Python?
A: Keywords are reserved words in Python which have special meaning. Example: if, for,
while, def.
Q9: What are identifiers?
A: Identifiers are the names used for variables, functions, classes, etc.
Q10: What is a variable in Python?
A: A variable is used to store data. It does not need to be declared with a type.
Q11: Give an example of an if-elif-else statement.
A:
X = 10
If x > 0:
Print(“Positive”)
Elif x == 0:
Print(“Zero”)
Else:
Print(“Negative”)
Q12: What is the difference between == and is?
A: == checks value equality, is checks object identity.
Unit II: Data Structures in Python
Q1: What is a list in Python?
A: A list is a collection of items which is ordered and changeable. It is defined using
square brackets [].
Q2: What is a tuple?
A: A tuple is a collection of items which is ordered but unchangeable (immutable). It is
defined using parentheses ().
Q3: What is a set?
A: A set is a collection of unordered and unique items. It is defined using curly braces {}.
Q4: What is a dictionary?
A: A dictionary stores data in key-value pairs. It is defined using curly braces with keys
and values: {key: value}.
Q5: Name two list methods.
A: append(), remove().
Unit III: Functions, Modules and Packages
Q1: How do you define a function in Python?
A: Using the def keyword.
Example: def greet(): print(“Hello”)
Q2: What is a lambda function?
A: It is a small anonymous function defined using the lambda keyword.
Example: lambda x: x*x
Q3: What is a module in Python?
A: A module is a file containing Python code (functions, variables) which can be
imported and used in another program.
Q4: What is PIP?
A: PIP is a package manager for Python used to install and manage Python packages.
Q5: What are the types of function arguments in Python?
A: Positional, Keyword, Default, and Variable-length arguments.
Q6: What is the difference between return and print()?
A: return gives back a value to the caller, print() just displays output.
Q7: What is the purpose of __name__ == “__main__”?
A: It is used to check whether the script is being run directly or being imported.
Q8: Give an example of importing a built-in module.
A:
Import math
Print(math.sqrt(25))
Q9: How do you install a package using pip?
A: pip install package_name
Unit IV: Object-Oriented Programming in Python
Q1: What is a class and object?
A: A class is a blueprint for creating objects. An object is an instance of a class.
Q2: What is a constructor in Python?
A: A constructor is a special method called automatically when an object is created.
Defined using __init__().
Q3: What is method overloading?
A: Defining multiple methods with the same name but different arguments (not fully
supported in Python, can be handled manually).
Q4: What is inheritance?
A: It is the process where one class can inherit properties and methods of another
class.
Q5: What is self in Python?
A: self refers to the current instance of the class and is used to access variables and
methods.
Q6: What is method overriding?
A: Defining a method in the child class with the same name as in the parent class to
change its behavior.
Q7: What is encapsulation?
A: Encapsulation is the concept of hiding internal details of a class. It is done using
private variables.
Q8: Give an example of inheritance.
A:
Class A:
Def show(self):
Print(“A class”)
Class B(A):
Pass
Obj = B()
Obj.show()
Unit V: Built-in Packages
Q1: What is pandas used for?
A: Pandas is used for data analysis and manipulation. It provides structures like Series
and DataFrames.
Q2: What is a DataFrame in pandas?
A: A DataFrame is a 2D labeled data structure (like a table with rows and columns).
Q3: What is tkinter?
A: tkinter is a GUI library in Python used to create windows, buttons, labels, etc.
Q4: How do you connect Python with MySQL?
A: Using mysql-connector package. We create a connection and use cursor object to
execute SQL queries.
Q5: How do you create a pandas Series?
A:
Import pandas as pd
S = pd.Series([1, 2, 3])
Q2: How do you read a CSV file in pandas?
A: pd.read_csv(‘filename.csv’)
Tkinter:
Q6: What is the use of tkinter?
A: It is used to create graphical user interfaces (GUIs) in Python.
Q7: Name any two tkinter widgets.
A: Label, Entry, Button, Checkbutton.
MySQL:
Q8: How do you execute a query in MySQL using Python?
A:
Cursor.execute(“SELECT * FROM table_name”)
Q9: What does fetchall() do?
A: It retrieves all rows from the result of a query.