MoonGame/SubstringÜA21.10.py
2025-10-30 20:05:43 +01:00

17 lines
656 B
Python

def subject(source:str, start_index:int, symbol_count:int=None)-> str:
if start_index > len(source):
raise ValueError('start_index must be smaller than the length of source')
if symbol_count is None:
symbol_count = len(source)-start_index
if start_index+symbol_count > len(source):
raise ValueError('start_index must be smaller than the length of source')
if start_index < 0:
raise ValueError('start_index must be positive')
return source[start_index:start_index+symbol_count]
if __name__ == '__main__':
original = 'GEEKSFORGEEKS'
print(subject(original, 0, 5))
print(subject(original, 5))