add modules
This commit is contained in:
parent
38cbcdf611
commit
101004be51
@ -258,7 +258,6 @@ match day:
|
||||
print("I love weekends!")```])
|
||||
|
||||
|
||||
|
||||
=== Schleifen
|
||||
==== for-loop
|
||||
Alle Items werden ausgeprintet.
|
||||
@ -322,6 +321,103 @@ Erklärung:
|
||||
- ```py return something ```: Falls etwas zurückgegeben werden möchte kann dies mitels return gemcht werden. Es ist auch möglich mehere variabeln zurückzugeben z.b. ```py f, p = return x, y ```. Falls nicht zurückgegeben werden möchte kann auf dass return verzichtet werden.
|
||||
Optionale Parameter kommen immer am schluss!
|
||||
|
||||
=== Module
|
||||
#grid(columns: (1fr, 1fr),[
|
||||
Um die Funktionen im *main.py* nutzen zu können gibt es vier mehtoden um die funktionen ui Importieren. Hier Beispiel mit *functions.py*.
|
||||
], [
|
||||
*functions.py*
|
||||
#table(columns: 1fr, [```py
|
||||
def function_a () :
|
||||
pass
|
||||
def function_b () :
|
||||
pass
|
||||
def function_c () :
|
||||
pass
|
||||
```])
|
||||
])
|
||||
#table(columns: (0.5fr, 1fr),
|
||||
[Nur die notwendigen Funktionen Importieren], [```py
|
||||
from functions import function_a, function_b
|
||||
print(function_a())
|
||||
```],
|
||||
[Nur das Modul Importieren], [```py
|
||||
import functions
|
||||
print(functions.function_a())
|
||||
```],
|
||||
[Alle Funktionen Importieren \ *nicht empfohlen!*], [```py
|
||||
from functions import *
|
||||
print(function_a ())
|
||||
```],
|
||||
[Modul als Alias Importieren], [```py
|
||||
import pandas as pd
|
||||
pd.read_csv()
|
||||
```],
|
||||
[Funktion als Alias Importieren], [```py
|
||||
from functions import function_a as a
|
||||
print(a())
|
||||
```],
|
||||
)
|
||||
==== Bekannte Module
|
||||
- *pandas*: powerful Python data analysis toolkit
|
||||
- *numpy*: NumPy is the fundamental package for scientific computing with Python
|
||||
- *scikit-learn*: A set of python modules for machine learning and data mining
|
||||
- *plotly*: An open-source, interactive data visualization library for Python
|
||||
- *matplotlib*: A library for creating static, animated, and interactive visualizations in Python.
|
||||
|
||||
==== Autostart beim import
|
||||
*ACHTUNG*: Module werden beim Import in einem anderen Modul ausgeführt!
|
||||
#grid(columns: (1fr, 1fr, 0.8fr), gutter: 10pt,[
|
||||
*main.py*
|
||||
#table(columns: 1fr, [```py
|
||||
import my_functions
|
||||
name = "Marco"
|
||||
print_hallo(name)
|
||||
```])
|
||||
], [
|
||||
*my_functions.py*
|
||||
#table(columns: 1fr, [```py
|
||||
def print_hallo(name):
|
||||
print(f"{name}")
|
||||
print_hallo("Marco")
|
||||
```])
|
||||
], [
|
||||
*Output*
|
||||
#table(columns: 1fr, [```py
|
||||
"Marco"
|
||||
"Marco"
|
||||
```])
|
||||
])
|
||||
Um dieses Verhalten zu unterdrücken, muss der code mit der folgenden Zeile ergänzt werden.
|
||||
#table(columns: 1fr, [```py
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
```])
|
||||
#grid(columns: (1fr, 1fr, 0.8fr), gutter: 10pt,[
|
||||
*main.py*
|
||||
#table(columns: 1fr, [```py
|
||||
import my_functions
|
||||
name = "Marco"
|
||||
print_hallo(name)
|
||||
```])
|
||||
], [
|
||||
*my_functions.py*
|
||||
#table(columns: 1fr, [```py
|
||||
def print_hallo(name):
|
||||
print(f"{name}")
|
||||
if __name__ == "__main__":
|
||||
print_hallo("Marco")
|
||||
```])
|
||||
], [
|
||||
*Output*
|
||||
#table(columns: 1fr, [```py
|
||||
"Marco"
|
||||
```])
|
||||
])
|
||||
|
||||
=== Daten Lese und Schreiben
|
||||
==== csv
|
||||
==== json
|
||||
|
||||
|
||||
|
||||
=== Runden
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user