Py学习  »  Python

在python中同时创建多个矫揉造作的函数

pythonstudent27 • 4 年前 • 1808 次点击  

我是python新手,目前正在学校完成一个项目。 如果我要写一个名为 inputfunction() 其工作原理如下:

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

我真的不知道从哪里开始。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/130180
文章 [ 1 ]  |  最新文章 4 年前
Samwise
Reply   •   1 楼
Samwise    4 年前

将两个不同的值作为元组返回。

>>> 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]