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

Creating a function for multiple affectation at once in python

I’m new to python and I’m currently completing an project for school.
How would I proceed if I were to write a function named inputfunction() that would work as follow:

var1, coordinates = inputfunction()
"enter var1": 0
"enter coordinates" (x,y): 0,1
>>> print(var1)
0
>>> print(coordinates)
[0, 1]

I really don’t know where to start.

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 :

Return the two different values as a tuple.

>>> def inputfunction() -> tuple[int, list[int]]:
...     return (
...         int(input('"enter var1": ')),
...         [int(n) for n in input('"enter coordinates" (x,y): ').split(",")]
...     )
...
>>> var1, coordinates = inputfunction()
"enter var1": 0
"enter coordinates" (x,y): 0,1
>>> print(var1)
0
>>> print(coordinates)
[0, 1]
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