多值返回功能。可能吗?

时间:2015-05-20 06:19:18

标签: python-3.x

这是一个普遍的问题。

如何从函数中返回多于1个值,是否可能? 例如, 我在任意游戏中制作得分计数器,我有三个变量:

  1. my_score
  2. comp_score
  3. 接下来,我有一个函数,其中有各种if,elif条件取决于上述任何变量的更新。

    我调用函数并且变量相应地更新,但现在我想要一个print语句打印得分下的所有三个变量 等,

    print(" Score: Mine = {} , Comp = {} , Tied = {} ".format()) 
    /*I need to enter three variables here inside .format() of which any one is updated and returned from the function according to the condition. But calling the function returns only one value*/
    

    我该怎样做才能实现这一目标?

    同样,当调用函数时,计数器再次从0开始,因为我在开始时将三个变量初始化为0。我该怎么做才能让计数器继续更新值并正确打印其中的三个?

    提前致谢!

0 个答案:

没有答案