Python is an incredibly flexible yet powerful language. One of the weirdest quirks about python is how everything is an object aka a class. There are no primitive data types like int or char in C++.
My only tip is to really understand what’s going on in the background when you write a line like this “ X = []”. This line of code creates a list object and assigns the variable X as a reference to the object. So if you then type “Y = X”, this second line of code just creates a new variable Y that is a reference to the same mutable (editable) list that you previously created. This second line does not copy the object or create a new one. It creates a second reference variable to the same underlying object, so basically an alias variable. This will feel weird if you’re used to other languages like C++ where function calls and assignment are automatically by copy unless explicitly changed to a reference.
2
u/PranDopp 10d ago
Python is an incredibly flexible yet powerful language. One of the weirdest quirks about python is how everything is an object aka a class. There are no primitive data types like int or char in C++.
My only tip is to really understand what’s going on in the background when you write a line like this “ X = []”. This line of code creates a list object and assigns the variable X as a reference to the object. So if you then type “Y = X”, this second line of code just creates a new variable Y that is a reference to the same mutable (editable) list that you previously created. This second line does not copy the object or create a new one. It creates a second reference variable to the same underlying object, so basically an alias variable. This will feel weird if you’re used to other languages like C++ where function calls and assignment are automatically by copy unless explicitly changed to a reference.