# StringEquality.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-26 File created. # 2022-12-16 Converted to Python 3. # Operator == compares objects. # Operator 'is' chan check whether two names reference # the same object. first_string = "aaaaaa" second_string = "bbbbbb" print( "\n " + first_string + " " + second_string, end="" ) if first_string == second_string : print( "\n Equal objects.", end="" ) else : print( "\n Not equal objects.", end="" ) if first_string is second_string : print( "\n Referencing the same object.", end="" ) else : print( "\n Different objects referenced.", end="" ) second_string = first_string print( "\n " + first_string + " " + second_string, end="" ) if first_string == second_string : print( "\n Equal objects.", end="" ) else : print( "\n Not equal objects.", end="" ) if first_string is second_string : print( "\n Referencing the same object.", end="" ) else : print( "\n Different objects referenced.", end="" ) # The following statement makes an identical copy of the first string second_string = first_string[ 0 : 2 ] + first_string[ 2 : ] print( "\n " + first_string + " " + second_string, end="" ) if first_string == second_string : print( "\n Equal objects.", end="" ) else : print( "\n Not equal objects.", end="" ) if first_string is second_string : print( "\n Referencing the same object." ) else : print( "\n Different objects referenced." )