Intern
# You need to write a function f that subtracts the second string from the first. # Subtraction occurs only when the second string is the beginning of the first, # otherwise the function returns the first string. # f('hello world', 'hello') -> ' world' # f('hello world', 'hola') -> 'hello world' # f('hello world hello!', 'hello') -> ' world hello!'
sobes.tech AI
Answer from AI
python def f(s1: str, s2: str) -> str: if s1.startswith(s2): return s1[len(s2):] return s1
Примеры:
print(f('hello world', 'hello')) # ' world' print(f('hello world', 'hola')) # 'hello world' print(f('hello world hello!', 'hello')) # ' world hello!'