Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = [1,2]; // a has an array
- b = &a; // b points to a
- *b = 2; // derefernce b to store 2 in a
- print(a); // outputs 2
- print(*b); // outputs 2
- class ref:
- def __init__(self, obj): self.obj = obj
- def get(self): return self.obj
- def set(self, obj): self.obj = obj
- a = ref([1, 2])
- b = a
- print a.get() # => [1, 2]
- print b.get() # => [1, 2]
- b.set(2)
- print a.get() # => 2
- print b.get() # => 2
- func()
- {
- var a = 1;
- var *b = &a;
- *b = 2;
- assert(a == 2);
- }
- a = [1]
- b = a
- b[0] = 2
- assert a[0] == 2
- a = [1,2] // a has an array
- b = a // b points to a
- a = 2 // store 2 in a.
- print(a) // outputs 2
- print(b) // outputs [1,2]
- >>> a = [1,2]
- >>> id(a)
- 28354600
- >>> b = a
- >>> id(a)
- 28354600
- >>> id(b)
- 28354600
- # Change operations like:
- b = &a
- # To:
- b = "a"
- # And change operations like:
- *b = 2
- # To:
- locals()[b] = 2
- >>> a = [1,2]
- >>> b = "a"
- >>> locals()[b] = 2
- >>> print(a)
- 2
- >>> print(locals()[b])
- 2
Add Comment
Please, Sign In to add comment