1

I want to be able to modify a variable. F.e. :

b = 0
setbit(b,4)

I expect b to become 16. But as we know python is pass-by-assignment, not pass-by-value or pass-by-reference. My question is : Is this possible in some other way ?

The best shortcut I've come up with is :

def nbit(n) : return 1 << n

and then :

b |= nbit(4)

I would prefer a function like the first example.

sten
  • 7,028
  • 9
  • 41
  • 63

0 Answers0