''' Purpose: considers how Python stores and keeps track of variables ''' # get inputs into proper form (string and integer) w = input( 'Enter word: ' ) si = input( 'Enter integer: ' ) sd = input( 'Enter decimal: ' ) print() # Printing the variable prints out the value! # print(w) will print out the value of w # word you typed since the word input was stored in variable w! print( 'w: ', w ) print( 'si: ', si ) print( 'sd: ', sd ) print() # type( x ) tells you what the type of x is (int, str /string, float, etc.) # id( x ) tells you the location in memory (id) that x has in your program # Tells you where in memory you can find that variable # Remember Python allocates memory to store variables / values (like those boxes earlier) # and we can use Python unique ids to reference specific variables in memory. # Remember: Variables are stored in memory (each variable has a location in memory and that # location can be found using id(variable) ) w_type = type( w ) w_id = id( w ) si_type = type( si ) si_id = id( si ) sd_type = type( sd ) sd_id = id( sd ) # display what we found out print( 'variable w is', w_type, 'and is at', w_id, 'and when printed displays', w ) print( 'variable si is', si_type, 'and is at', si_id, 'and when printed displays', si ) print( 'variable sd is', sd_type, 'and is at', sd_id, 'and when printed displays', sd ) print() # let's cast (convert) si and sd respectively into an integer and decimal i = int( si ) d = float( sd ) print( 'i: ', i ) print( 'd: ', d ) print() i_type = type( i ) i_id = id( i ) d_type = type( d ) d_id = id( d ) # display what we found out # Previously, si and sd were strings of the int i and float d before we converted them in lines 50-51. print( 'variable i is', i_type, 'and is at', i_id, 'and when printed displays', i) print( 'variable d is', d_type, 'and is at', d_id, 'and when printed displays', d )