from typing import Optional


def substring(string: str, start: int, end: Optional[int] = None) -> str:
    """Returns a section of string between the start and end indices."""
    start = max(0, int(start))
    end = len(string) if end is None else max(0, int(end))
    if start > end:
        end, start = start, end
    return string[start:end]