def tail_factorial(n, accumulator=1):
    """ Returns the factorial of an integer.

    The calculation is done by tail recursion.

    :param n: the integer of which the factorial is desired to return
    :param accumulator: default to be 1, for tail recursion.
    :return: factorial of `n`
    :type n: int
    :type accumulator: int
    :rtype: int
    """
    if n == 0:
        return accumulator
    else:
        return tail_factorial(n-1, accumulator * n)