0

I am new to python and started learning from internet and youtube. I have a question as "Why is the memory location of two variables is same for the different integer variable's declared separately in Python?"

a=[1,2,3]
b=[1,2,3]

print(a==b)
print(a is b)

this give the result as

False  
True

but when i try the below the result is "True" for both the cases. Why is it?

a=1
b=1
print(a==b)
print(a is b)

As i am new to programming languages, help me with some free websites where I can get a structured way to learn python with videos and practice exercise with real word examples. That could help me become a data scientist.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
AlphaBet
  • 156
  • 1
  • 4
  • 1
    Are you sure that's the output you got? https://ideone.com/MW6n1w – Oliver Charlesworth Nov 19 '17 at 17:22
  • @Oliver Charlesworth: Yes ! – AlphaBet Nov 19 '17 at 17:25
  • @snakecharmerb, Can you please help me with the original question where I could find the answers? – AlphaBet Nov 19 '17 at 17:32
  • I am curious why someone claiming to be new to programming languages is making assumptions about Python variables that can only come from descriptions of other languages. Python isn't telling you anything about the memory location of the variables (they are [names](https://nedbatchelder.com/text/names1.html), one of very few things that are *not* first class objects in Python). – Yann Vernier Nov 19 '17 at 17:47

0 Answers0