Die Basics (in Python)
Eingabe / Ausgabe bzw. Variablen
variable = input("Eingabe >> ")
print("Ausgabe: ", variable)
Datentypen
variable_1 = 123
variable_2 = 1.23
variable_3 = "abc"
variable_4 = False or True
array_1 = [0, "a", False]
array_2 = (1.0, "b", True)
Verzweigungen
if variable_4:
print("True")
elif variable_3 == "Abc":
print("Abc")
else:
print(None)
Funktionen
def FuncName(a, b, c, x):
y = (a * pow(x, 2)) + (b * x) + c
print(a, "*", str(x) + "^2 +", b, "*", x, "+", c, "=", y)
return y
quad_ergebnis = FuncName(1, 2, 3, 4)
print(quad_ergebnis)
Loops
for element in array_1:
print(element)
for index in range(0, len(array_1)):
element = array_1[index]
print(index, element)
index_2 = 0
while index_2 < len(array_1):
element = array_1[index_2]
print(index_2, element)
index_2 += 1
end_time = time.time()
Module
import time
start_time = time.time()
Dateisystem
file_handle = open("dateiname.dateiendung", "r")
file_read = file_handle.readlines()
file_handle.close()
print(file_read)
Klassen
class ClassName:
def __init__(self):
self.inner_variable = False
print("Initializing..")
def InnerFunc(self, inner_variable = None):
if not type(inner_variable) == bool:
inner_variable = not self.inner_variable
self.inner_variable = inner_variable
return self.inner_variable
def __str__(self):
return str(self.inner_variable)
ClassInstance = ClassName()
print(ClassInstance)
iv = ClassInstance.InnerFunc()
print(iv, ClassInstance)
iv = ClassInstance.InnerFunc(False)
print(iv, ClassInstance)
array_3 = []
array_3.append(array_1)