Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass different variables to multiple functons – python

I am very new to python and I have three lists that I edited in a function and want to pass these three lists to multiple different functions,
This is basic example of what I mean:

def editing():
    firstlist = [1,2,3]
    seclist = [4,5,6]
    thirdlist = [7,8,9]

def aa():


def bb():

I would like to send firstlist to aa() and all three lists to bb() but I am confused. What would be the most efficient way to do that?
thank you in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could work with global variables, but that is not good practice. Instead, return the lists from your function, as a tuple, and pass them as arguments into the other function.

def editing():
    firstlist = [1,2,3]
    seclist = [4,5,6]
    thirdlist = [7,8,9]

    return firstlist, seclist, thirdlist


def aa(firstlist):
    pass


def bb(firstlist, seclist, thirdlist):
    pass


one, two, three = editing()
aa(one)
bb(one, two, three)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading