What is content and reference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is content and reference?

L1=["sachin"]

17th May 2021, 5:27 PM
Sachin Pradhan
Sachin Pradhan - avatar
3 Answers
+ 6
Hi! L1 is a variable with a referens to a memory adress where a list is stored. The content of the list is the string ”sachin”.
17th May 2021, 5:43 PM
Per Bratthammar
Per Bratthammar - avatar
+ 2
Using ’[’ and ’]’ is one way to create a list. Using list() is another way to create a list. For example my_list = [1, 2, 3]. But if you create a list, and want to use it later, you have to store it somewhere in the memory. Python chooses that place for you, and that place has a memory adress. To make it easy for you, you just create a variable (here my_list), and assign your list to that variable as shown above. ‘Inside’ my_list there is the adress (which you can’t normaly see) to the place in memory where the list is stored. So your variable my_list now containing a referens (the adress) to the list in the memory. And now you can write the name of the variable, instead of create a new list, when you want to use a list like that: print(my_list) >> [1, 2, 3]
17th May 2021, 6:17 PM
Per Bratthammar
Per Bratthammar - avatar
0
Mean you say that, here the reference is [] list data type and the content is sachin. Am right?
17th May 2021, 5:53 PM
Sachin Pradhan
Sachin Pradhan - avatar