python - apply Operation on multiple variables

后端 未结 6 2004
梦谈多话
梦谈多话 2021-01-27 12:26

I know that this is a rather silly question and there are similar ones already answered, but they don\'t quite fit, so... How can I perform the same operation on multiple variab

6条回答
  •  有刺的猬
    2021-01-27 12:57

    Map is your friend here, but you also need to use 'implicit tuple unpacking':

    >>> a = 3
    >>> b = 4
    >>> c = 5
    >>> d, e, f = map(lambda x: x * 2, [a, b, c])
    >>> d
    6
    >>> e
    8
    >>> f
    10
    

    This way you can get the changed values back without modifying the original values

提交回复
热议问题