call-by-reference function parameters

后端 未结 4 1059
挽巷
挽巷 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:41

    You can do this if c is a list:

    c = [2]
    def A(a, b, c):
        a *= 2
        b *= 4
        c[0] *= 8
        return a+b+c[0]
    print c  # gives [16]
    

提交回复
热议问题