Hi,what is the meaning of this phrase | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hi,what is the meaning of this phrase

Lists in Python, like most things, do not actually contain the items inside them. Rather, they contain references

5th Jan 2020, 8:16 PM
Yusof
Yusof - avatar
2 Answers
+ 1
Python stores every value somewhere in memory, you don't get to see it. In lists, but also generally, only the addresses are stored. Basically when you say: print(x) You are saying: Please go to the place with the name (reference) x and return me that value. This is important, because any object in Python can have several references. a = [] gives the name a to a list that is newly created b = a creates no new list, but gives another name b to the very same list a. So two references point to only one object in computer memory, although it looks like you have two separate lists a and b. Often mistakes happen, because people add something to their list... a.append('Whatever') ... and expect that b is still empty. Now if they write... print(b) ...the word Whatever is printed. Because when they appended to a, they also appended to b - because it's the same list in reality.
5th Jan 2020, 8:24 PM
HonFu
HonFu - avatar
0
Python list can store every value. For example: A=["NIG",132,132.0,{1,2},{1:2}] In this list you can see that there is every type of object.
6th Jan 2020, 1:34 AM
Nig