passing variables between functions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

passing variables between functions

rulrul Posts: 8Member
how do i pass variables from one function to another in python?

Comments

  • infidelinfidel Posts: 2,900Member
    : how do i pass variables from one function to another in python?

    Same way you passed them to the first function.

    [code]
    def func1(x, y):
    return func2(x, y, 1, 2)

    def func2(a, b, c, d):
    return a + b + c + d

    print func1(8, 9)
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • egroveegrove Posts: 3Member
    def function(x, y):
    total = x + y
    return total

    def main():
    a = 5
    b = 10
    total = function(a,b)
    print a, b, total

    main()

    By doing this you can pass args from main to a function and can get back any value by returning from that function.
Sign In or Register to comment.