Python Forum
Call to a print in a defined function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to a print in a defined function
#1
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?
Reply


Messages In This Thread
Call to a print in a defined function - by leodavinci1990 - Nov-20-2019, 12:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 340 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 636 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,419 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 830 May-02-2023, 08:40 AM
Last Post: Gribouillis
  How to print variables in function? samuelbachorik 3 954 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  Getting NameError for a function that is defined JonWayn 2 1,156 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,979 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,354 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  User-defined function to reset variables? Mark17 3 1,701 May-25-2022, 07:22 PM
Last Post: Gribouillis
  Why does absence of print command outputs quotes in function? Mark17 2 1,427 Jan-04-2022, 07:08 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020