call-by-reference function parameters

后端 未结 4 1081
挽巷
挽巷 2021-01-15 02:03

Given a function:

def A(a, b, c):
    a *= 2
    b *= 4
    c *= 8
    return a+b+c

How can I set the \'c\' var to be called-by-reference,

4条回答
  •  不要未来只要你来
    2021-01-15 02:32

    You can't. Python cannot do that.

    What you can do is pass a wrapper that has __imul__() defined and an embedded int, and the augmented assignment will result in the embedded attribute being mutated instead.

提交回复
热议问题