Python Forum
i don't understand how to use a variable outside of a function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i don't understand how to use a variable outside of a function?
#7
Any function returns an object which you can assign to a variable.
So you define one. Simplified because I am lazy today:
def test(arg):
    return a
Then define another:
def second(some_argument):
    b = test(some_argument)
    if b != 'stupid example':
        return 'Good enough'
Now call 'second':
s = 'No?'
second(s)
You can pass any argument to a function and use it inside another one. some_argument could be any python object, however, it is called. Of course, its type has to be suitable to use it at all.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: i don't understand how to use a variable outside of a function? - by wavic - Oct-04-2017, 06:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable for the value element in the index function?? Learner1 8 671 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 602 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,337 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 954 Aug-07-2023, 05:58 PM
Last Post: Karp
  Retrieve variable from function labgoggles 2 1,056 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Cant transfer a variable onto another function KEIKAS 5 1,906 Feb-09-2022, 10:17 PM
Last Post: deanhystad
  Don't Understand Recursive Function muzikman 9 3,723 Dec-03-2020, 05:10 PM
Last Post: muzikman
  Please explain uncommon way of declaring and using variable [function.variable] esphi 4 2,344 Nov-07-2020, 08:59 AM
Last Post: buran
  Spyder Quirk? global variable does not increment when function called in console rrace001 1 2,237 Sep-18-2020, 02:50 PM
Last Post: deanhystad
  passing variable to function Rejoice 4 2,887 Sep-11-2020, 03:27 AM
Last Post: Pleiades

Forum Jump:

User Panel Messages

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