def expandtabs(string, n):
    result = ''
pos = 0
for char in string:
    if char == '\t':
        char = ' ' * (n - pos % n)
if char == '\n':
    pos = 0
else:
    pos += len(char)
result += char
Строковая операция Python expandtabs