1• Define Function and its types:
• A function is a block of code which only runs when it is called. It can accept input
parameters, perform operations, and return a result. Functions help in code reusability
and modularity.
• Types of functions:
o Built-in functions: These are functions that are pre-defined in Python (e.g.,
print(), len(), type()).
o User-defined functions: These are functions defined by the user using the
def keyword.
o Lambda functions: These are small anonymous functions defined using the
lambda keyword.
2• Define Argument:
• An argument is a value that is passed to a function when it is called. Arguments are
specified after the function name, inside the parentheses.
3• Define Keyword Argument:
• A keyword argument is an argument passed to a function by explicitly stating the
parameter name and value in the function call. This allows for more readable code
and the arguments can be passed in any order. For example, func(name='John',
age=30).
4• Define Default Argument:
• A default argument is an argument that assumes a default value if a value is not
provided in the function call. They are defined by specifying the default value in the
function definition. For example, def func(name='John'):.
5• What is a Lambda Function?
• A lambda function is a small anonymous function defined with the lambda keyword.
It can take any number of arguments but has only one expression. For example,
lambda x, y: x + y.
6• What is a Global and Local Variable?
• Global variable: A variable that is defined outside of any function and can be
accessed globally throughout the module.
• Local variable: A variable that is defined within a function and can only be accessed
within that function.
7• What is a Module?
• A module is a file containing Python definitions and statements. It can include
functions, classes, and variables. Modules help in organizing code into manageable
sections and can be imported into other modules using the import statement.
8• Define Object-Oriented Programming (OOP):
• Object-oriented programming is a programming paradigm that uses objects and
classes to structure software. It is based on the concepts of "objects", which are
instances of classes, encapsulating data and behavior together.
9• List Benefits of OOP:
• Encapsulation: Bundling data with methods that operate on the data.
• Abstraction: Hiding complex implementation details and showing only the necessary
features.
• Inheritance: Allowing new classes to inherit attributes and methods from existing
classes.
• Polymorphism: Allowing different classes to be treated as instances of the same class
through interfaces.
10• Explain __init__ Method:
• The __init__ method is a special method in Python classes known as a constructor.
It is automatically called when a new instance of the class is created. It initializes the
object's attributes.
11• Difference between Error and Exception:
• Error: Errors are problems in the program that usually cannot be recovered from.
Examples include syntax errors and logical errors.
• Exception: Exceptions are events that can disrupt the normal flow of a program's
instructions. They can be handled using try-except blocks. Examples include
ZeroDivisionError, FileNotFoundError.
12• Define Exception:
• An exception is an event that occurs during the execution of a program that disrupts
the normal flow of the program's instructions. Exceptions can be caught and handled
using try-except blocks.
13• List Different Types of Argument Passing Methods in Python:
• Positional arguments: Arguments passed to a function based on the order.
• Keyword arguments: Arguments passed to a function by explicitly specifying the
parameter name.
• Default arguments: Arguments that assume a default value if not provided in the
function call.
• Variable-length arguments: Allows a function to accept any number of arguments
using *args (non-keyword arguments) and **kwargs (keyword arguments).
10 marks