Python Forum

Full Version: Call to a print in a defined function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def fib(n):    # write Fibonacci series up to n
    """Print a Fibonacci series up to n."""
    a = 0
    b = 1
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()
# Now call the function we just defined:
fib(2000)
The output for this function is:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597

My question is what is the function of the last print() function in the function since it has no arguments to print?
The end parameter of print defaults to '\n'. By providing a value for that parameter, the function never goes to the next line. The final print, with no arguments, is there to move the standard output to the next line.