Lesson 21 of 55 · Python
Modules and Packages
Duration: 20 minutes
Modules and Packages\n\nA module is a single .py file that can be imported. A package is a directory containing an __init__.py file, allowing you to group related modules together.\n\n```python\n# my_module.py\ndef hello(name):\n return f'Hello, {name}!'
\n# In another script\nimport my_module\nprint(my_module.hello('Bob'))\n```\n\nOrganizing code into modules and packages makes large projects easier to maintain and reuse.\n