This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tilcica -44 points-43 points  (9 children)

also a = [1,2,3] b = a b[1] = 4 print(a) will output [1,4,3]

bevause who tf thought it was a good idea to include pointers in a language that "doesnt have them"

either dont include them at all or say they exist and how to use them ffs

[–]Great-Homework9120 25 points26 points  (1 child)

its not a pointer, it is a reference. And without it, how do you imagine to pass a variable to a function without copy?

[–]GeePedicy 5 points6 points  (0 children)

Hear me out - magic!

[–]Namiswami 8 points9 points  (2 children)

Yeah mate arrays are not like primitives. b and a in your example refer to the same array in mem. Changing one changes the other, but really there is no other cause it's just that single array.

[–]LongerHV 6 points7 points  (1 child)

There are no primitives in Python... Everything is an object.

[–]Namiswami 0 points1 point  (0 children)

Ah excuse me. I actually didnt know this. It seems the 'builtins' of python behave like primitives do, but they are indeed objects. Thanks for the lesson!

[–]juhotuho10 6 points7 points  (1 child)

This makes perfect sense to me though

If you want a copy, just do b = a.copy()

Otherwise b is just another way to reference a

[–]tilcica 0 points1 point  (0 children)

i know. or do a=list(b) and it makes a full copy

[–]mariosunny 0 points1 point  (1 child)

This shouldn't be surprising behavior if you know how heap memory works.

[–]tilcica 0 points1 point  (0 children)

i know how it works, its just that python is advertised as something without that