yo
This commit is contained in:
commit
a8ee8bad99
7 files changed
+458
No files matched your search
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Teilt den String an gewünschter Position und gibt ihn geteilt aus 👌
|
||||
"""
|
||||
|
||||
def substring(text:str, start:int, length:int|None=None)->str:
|
||||
|
||||
if start < 0 or start > len(text):
|
||||
raise ValueError(f"Invalid position: {start}")
|
||||
#Fehlerausgabe, wenn die Startposition außerhalb des Bereichs der Länge liegt
|
||||
|
||||
if length is not None:
|
||||
if length < 0:
|
||||
raise ValueError(f"Invalid: {length}")
|
||||
#Fehlerausgabe, wenn Länge kleiner 0 ist
|
||||
return text[start: start + length]
|
||||
#Gibt den String ab der Startposition bis zum Ende wieder
|
||||
return text[start:]
|
||||
|
||||
|
||||
|
||||
text = "GEEKSFORGEEKS"
|
||||
print(substring(text, 5))
|
||||
print(substring(text, 0, 5))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user