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 .py:
Use a Module
Now we can use the module we just created, by using the import statement:
Note: When using a function from a module, use the syntax: module_name.function_name.
Variables in Module
The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc):
Naming a Module
You can name the module file whatever you like, but it must have the file extension .py
Re-naming a Module
You can create an alias when you import a module, by using the as keyword:
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 dir() function:
Note: The dir() function can be used on all modules, also the ones you create yourself.
Import From Module
You can choose to import only parts from a module, by using the from keyword.
Note: When importing using the from keyword, do not use the module name when referring to elements in the module. Example: person1["age"], not mymodule.person1["age"]
* Reference and Super Thanks : w3schools.com
파이썬 클래스 개념 (0) | 2023.04.17 |
---|---|
파이썬 detetime 모듈 개념 (0) | 2023.04.16 |
파이썬 상속 개념 (0) | 2023.04.14 |
format (0) | 2023.04.12 |
댓글 영역