Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the output of a function as the input for another function inside a function

I am currently studying Python and hoping someone could help me. I'm fairly new to coding so would be really helpful if its explained well.

Lets say I have a function called function1 that returns:

return (row, column)

Now I am writing another function called say function2. Within this function I need to call say:

exampleItem.exampleName(row, column, name)

How do I use the output of the function1 which is the row and column as the row and column arguments in the above line from function2?

I really hope this makes sense as I got seriously penalized for not writing a question properly before because I didn't realize the best practice here.

like image 595
Gazza732 Avatar asked Dec 05 '22 16:12

Gazza732


1 Answers

In all versions of Python you can do:

row, column = function1()
exampleName(row, column, name)

In more recent versions (3.5+) you can use unpacking to do things like:

exampleName(*function1(), name)

For further reading see: PEP 448 -- Additional Unpacking Generalizations.

like image 178
Patrick Haugh Avatar answered Jan 19 '23 00:01

Patrick Haugh