Unit IV: Python Functions and Packages

Table of Contents

1. Python Functions

Functions are sub-programs that carry out specific tasks. They help in code reusability and making complex programs easier to manage.


2. Function Arguments & Parameters

Arguments are values passed into a function when it is called. Parameters are the variables listed in the function definition.


3. Pass by Value vs Object Reference

Python uses a mechanism called Pass by Object Reference (also known as Pass by Assignment).


4. Recursion

Recursion is a programming technique where a function calls itself to solve a problem.


5. Scope and Lifetime of Variables

The scope of a variable defines where in the program it can be accessed. The lifetime is the period during which the variable exists in memory.


6. Python Modules and Packages

These are organizational tools for larger Python projects.

Exam Tips

Common Pitfalls


Frequently Asked Questions

Q: Is Python pass-by-value or pass-by-reference?
Neither. It is pass-by-object-reference. If the object is mutable, changes reflect outside; if immutable, they do not.

Q: What is the difference between a module and a library?
A module is a single file. A package is a collection of modules. A library is a collection of packages that provides specific functionality.