Python Modules | |||
![]() ![]() ![]() | |||
What is a Module? Consider a module to be the same as a code library. A file containing a set of functions you want to include in your application. Create a Module To create a module just save the code you want in a file with the file extension
Use a Module Now we can use the module we just created, by using the
Variables in Module The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc):
Import the module named mymodule, and access the person1 dictionary:
Naming a Module You can name the module file whatever you like, but it must have the file extension Re-naming a Module You can create an alias when you import a module, by using the
Built-in Modules There are several built-in modules in Python, which you can import whenever you like.
Using the dir() Function There is a built-in function to list all the function names (or variable names) in a module. The
Import From Module You can choose to import only parts from a module, by using the
Import only the person1 dictionary from the module:
Tags: Python Python Modules ![]() ![]() | |||
| |||
| |||
|
SIMILAR POSTSPython ScopePython PolymorphismPython IteratorsPython InheritancePython Classes/ObjectsPython ArraysPython LambdaPython FunctionsPython While Loops/For LoopsPython Conditions and If statementsPython DictionariesPython SetsPython TuplesPython Comparison OperatorsPython Arithmetic OperatorsPrinting string n timesString concatenation by join()Python ListsPython String OperationsPython Data TypesPython VariablesPython CommentsPython SyntaxPython Getting StartedPython IntroductionWhat is Python?Code Chronicles - A Caffeine-Fueled Journey into Data Software EngineeringMachine Learning Types and Programming LanguagesPython Tutorials for AP Computer Science Principles, Data Projects and High School InternshipMastering Excel Data Manipulation with Python |