>>> L1 = [10,20,30,40]

>>> L1 = [10,20,30,40]
>>> L2 = L1
>>> L1[0] = 0
>>> L1
[0, 20, 30, 40]
>>> L2
[0, 20, 30, 40]

Other urls found in this thread:

blog.regehr.org/archives/721
docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x
twitter.com/SFWRedditGifs

Dumb frogposter

dumb "dumb frogposter" poster

I didn't think python could get any worse.

dumb frogposter

>hurr durr I'm retarded

it's a toad

L2 = list(L1)
#this was very difficult

What the fuck is that backwards bullshit?

You are clearly defining it to be a list based on L1. In L1 = L2, you are stating they must be the same.

Oh boy, let's see this get to bump limit when a simple search could clear doubts and shitposts aside.

default assignment operator in C++ defines the same stupid behavior

No, that statement should assign L2 to L1's current values.
Except this shitty language, whatever it is, seems to turn L1 into a pointer or some backwards shit like that.

This just not work like that

>No, that statement should assign L2 to L1's current values.
Who said that? Retarded frogposter like you can't say what a language should do. Learn the language, fucking retard.

>Except this shitty language, whatever it is, seems to turn L1 into a pointer or some backwards shit like that.
Idiot, it doesn't turn anything to a pointer. Both variables are references.

It does my holy god

arent arrays/lists normally pass by reference in most languages? that is why with shit like python you can send a list as an argument and you dont have to return it to use it with changes

what's the point of "improve the readability" if you have to be an autist of the implementation details, just as in ANSI C bullshit

>>> fag1 = "OP"
>>> fag2 = fag1
>>> fag1 = "you"
>>> fag1
'you'
>>> fag2
'OP'

If were not a pajeet, you would understand. This is not an exotic behavior. A lot of other languages do this.

doesn't compile

...

in python you have to know what a reference is
in c
you have to deal with this
blog.regehr.org/archives/721

strings are immutable, lists are mutable
docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x

that wasn't too fair user, the c progamming language also explains these things, but you don't expect this behavior on higher languages, that's why STL and Modern C++ (Python++) overload the default assigment operator for each class
>great trivia though, I got 62%

This behavior is not stupid, you guys don't understand programming. Imagine a language that passed non primitive types by value, it would instantly become a bottleneck. Anytime you called a function with a list or other data structure as a parameter, all the contents of the list itself would have to be copied onto the call stack which would be horribly inefficient when dealing with lots of data. That's why pass by reference is a great thing.

Plus, almost all languages have built in functions for copying the actual data itself of a data structure and not its reference. The semantics of the assignment operator are fine, as it should be obvious when a variable is a reference.

>imagine a language that passed non primitive types by value
C++ does it, that's why you have and interface like >this

template
foo(T &value)
{
....

the & operator avoid passing an object by value, every programmer must know what a reference is, but
the behaviour of that simply snippet is a fucking joke

>compile

an array is a pointer, faggot.

take an elementary computer science course

>tfw no one can prove to me why meme language Python still exists.

let L2 = JSON.parse....

gee its almost as if you called a function instead of assigning a reference

>>>L2 = L1[:]
Try this and see the magic

I made a deep copy of an object, which is presumably what OP wanted to do in the first place. The method I used to get there shouldn't really matter.

Given that he never really specified wtf he's trying to do in the first place, I'd say it's a fairly safe bet to just assume that's what he wanted, and show a simple, commonplace way to do it in a non-fucked-up language.

>I'm pretending to be retarded again

>json.parse(json.stringify) is better than list(L1)
whatever you say bucko

What does it mean if I found this easy to understand?

Satisfied, bitchass motherfucker? You got scoped vars as a free added bonus

L1 = [10, 20, 30, 40]
L2 = [i for i in L1]

Is to izi

>>>L2 = L1[:]

I could've just done
const L2 = [...L1]

>what are reference types
This is exactly why people should learn C++ first.

No, this is why people should learn before shitposting.

Depends on language. Do you want to assignm a reference or a value. I prefer value, easier to work with