Python Forum
How do I print a returned variable calculated in another function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I print a returned variable calculated in another function?
#2
yearAt100 is local to the function yearThatYouTurn100. Once the function is over (after "return"), the variable ceases to exist for the rest of the program.

So what you should do is store the returned result in a variable, which you can then print:

def main():
    result = yearThatYouTurn100()
    print(result)
result will hold the value returned by the function.
This principle works generally for functions, and for any data types you might want to return.
Reply


Messages In This Thread
RE: How do I print a returned variable calculated in another function? - by j.crater - Jul-10-2018, 05:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 386 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Variable for the value element in the index function?? Learner1 8 768 Jan-20-2024, 09:20 PM
Last Post: Learner1
  How to access values returned from inquirer cspower 6 984 Dec-26-2023, 09:34 PM
Last Post: cspower
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 677 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,513 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 1,056 Aug-07-2023, 05:58 PM
Last Post: Karp
  Print variable without '' and spaces arnonim 1 772 Jan-30-2023, 05:23 PM
Last Post: deanhystad
  How to print variables in function? samuelbachorik 3 979 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  Problem with print variable in print.cell (fpdf) muconi 0 703 Dec-25-2022, 02:24 PM
Last Post: muconi
  How to calculated how many fail in each site(s) in csv files SamLiu 4 1,371 Sep-26-2022, 06:28 AM
Last Post: SamLiu

Forum Jump:

User Panel Messages

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