Modules in Python

ImportePakete

Modules are files containing Python code (functions, classes, variables) that you can import into other files. They help organize code, avoid repetition, and make programs easier to maintain.

Python comes with a rich standard library of modules, and you can create your own.

Importing Modules

Use import to load a module.

Import Specific Names

Use from ... import to import specific items.

Aliases with as

Creating Your Own Module

Save functions in a .py file and import it.

__name__ == "__main__" Guard

Run code only when file is executed directly, not when imported.

Quick Quiz

Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.

✨ Frag Lara — deine KI-Lernpartnerin

Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.


Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

Verfolge deinen Fortschritt 🚀

Lerne einfacher, indem du deinen Fortschritt kostenlos verfolgst.