[Tutor] Identity operator (basic types)

Christopher Lucas clucas916 at gmail.com
Sat Feb 10 06:45:11 CET 2007


On Feb 9, 2007, at 10:34 PM, Cecilia Alm wrote:

> Why does the identity operator return "True" in the below cases,  
> that is when assigning  the same value to basic variable types  
> (float, integer, string, bool..)? Are these rcopied by reference  
> (shallow)? If so why?
>
> >>> i = 10
> >>> j = 10
> >>> i is j
> True

Here you're saying that "i" is equal to 10 and that "j" is equal to  
10. Therefore "I' and "j" are the same

> >>> a = 10
> >>> b = a
> >>> a is b
> True
>

What you're saying here is that "a" is equal to 10. Then you say that  
the variable "b" is equal to the variable "a". Therefore you're  
saying that b equals 10 and that "a" and "b" are equal.

- Chris




More information about the Tutor mailing list