I did the same thing as him, created two lists1 and list2 with same elements. However, when I executed 'list1 is list2' system gave 'False'. Then I checked list1 and list2 values, but they were same. Why did it show False?
is gives true only if they are pointing to same objects. if you had written list1 = [1,2,3,4] and then list2 = list1, then you can expect the output of list1 is list2 as true.
22:37. Consider the following code, my_list = [1,2,3] new_list = my_list my_list = [4,5,6] If my_list and new_list point to the same data, why am I getting different outputs?
you are not pointing new list to my list as you are not using pointers. you made new list as my list and then changed my list so you will get different outputs
That is not true. when you assign a variable which has a immutable value type to another variable, you are creating two separate instances of object. You can easily check this in pythontutor.com
I agree with this initially they are pointing to the same location because print(id(x)) and print(id(y)) gives the same result , which means they are pointing to the same value . After updating the value of x , x started pointing to other address and y is still pointing to the initial location.
Command "cls" will clear the command prompt screen. Make sure you exit the python interpreter using the 'quit' or 'exit' command before typing "cls" as this command is not defined in python hence python will not recognize it.
These lectures are really good. Madhavan Sir, you are amazing.
Excellent explanations. Wish I did this course first. Shunned this course as an advanced course for a beginner in Python like me. 👍
By far the best teaching, i have come across, clearing the fundamental
Simply the best teacher I have ever come across in CS.
Amazing lectures Prof. Madhavan !!! Thank you for this.
Jp here again [Comment number 29]
Thank you, Sir, :)
Excellent💯💯
this id golden, he explained it so beautifully
Good explanation
really helpfull
I did the same thing as him, created two lists1 and list2 with same elements. However, when I executed 'list1 is list2' system gave 'False'. Then I checked list1 and list2 values, but they were same. Why did it show False?
is gives true only if they are pointing to same objects. if you had written list1 = [1,2,3,4] and then list2 = list1, then you can expect the output of list1 is list2 as true.
22:37. Consider the following code,
my_list = [1,2,3]
new_list = my_list
my_list = [4,5,6]
If my_list and new_list point to the same data, why am I getting different outputs?
you are not pointing new list to my list as you are not using pointers. you made new list as my list and then changed my list so you will get different outputs
I think both value pointed to same location when
x=5
y=x
but when
x=7
x is bound to new value and y remain to previous bounded value
That is not true. when you assign a variable which has a immutable value type to another variable, you are creating two separate instances of object. You can easily check this in pythontutor.com
I agree with this initially they are pointing to the same location because print(id(x)) and print(id(y)) gives the same result , which means they are pointing to the same value . After updating the value of x , x started pointing to other address and y is still pointing to the initial location.
I think L[:]==L[0:len(L) +1] but not L[:]==L[0:len(L) ]
No. It's not len(L)+1. It's len(L).
Because for len() we don't count from 0, we start from 1
Even your code will show the same result but the most efficient way to write the code is L[0:len(L)]
How do you clear the screen sir?
In python scripts, the screen cannot be cleared. There is no command to do that.
Command "cls" will clear the command prompt screen. Make sure you exit the python interpreter using the 'quit' or 'exit' command before typing "cls" as this command is not defined in python hence python will not recognize it.
Ed who?
Nice cheeks bro