''' Purpose: show for Python the differences between name, identity, value, and type ''' import pause # cs 1112 module print( 'This', 11, 'is a literal value' ) x = 12 print( 'This', x, 'is a value refered to by a variable; the variable "names" or "holds" the value' ) pause.enter_when_ready() ########################################################## print( 'Each value has a type:' ) print( 'type( ', 11, ' ) is', type( 11 ) ) print( 'type( ', 11.0, ' ) is', type( 11.0 ) ) print( 'type( ', "'11'", ' ) is', type( '11' ) ) pause.enter_when_ready() ########################################################## print( 'Each value also has an identity:' ) print( 'id( ', 11, ' ) is', id( 11 ) ) print( 'id( ', 11.0, ' ) is', id( 11.0 ) ) print( 'id( ', "'11'", ' ) is', id( '11' ) ) pause.enter_when_ready() ########################################################## print( 'The identify of a value is approximately "where it lives" in your computer' ) print( "Some other languages even call it the value's", '"address" instead of "id"' ) print( 'The id of a value might be different each time you run the same program' ) print() print( 'Some values might look the same, have the same type, but have distinct identities:' ) print() n1 = 11 n2 = round( 11.0 ) print( 'This', n1, 'has id', id( n1 ), 'and type', type( n1 ) ) print( 'This', n2, 'has id', id( n2 ), 'and type', type( n2 ) ) print( 'You can think of these values as being twins: alike but distinct' ) pause.enter_when_ready() ########################################################## print( 'The same variable might have different values in it at different times:' ) x = 12 print( 'x contains', x, 'which has id', id( x ), 'and type', type( x ) ) x = 11 print( 'x contains', x, 'which has id', id( x ), 'and type', type( x ) ) x = 'text' print( 'x contains', x, 'which has id', id( x ), 'and type', type( x ) ) pause.enter_when_ready() ########################################################## print( 'The memory for a Python variable points to where the value it represents' ) print( 'is stored; i.e., its id. \n') print( 'Therefore, multiple variables can have the same value at the same time.\n' ) print( 'The Python term for two variables with the same value is "aliases".\n' ) feeling = 'great' mood = feeling print( 'The value of feeling is', feeling, 'which has id', id( feeling ), 'and type', type( feeling ) ) print( 'The value of mood is', mood, 'which has id', id( mood ), 'and type', type( mood ) )