Python: Identity Operators

Post Reply
User avatar
Jason
Site Admin
Posts: 853
Joined: Tue Jul 01, 2025 10:13 am

Code: Select all

# Note: identity Operators do not tell if variables contain the same contents, but rather if they point to the same object

color_list_1 = list((orange, green, yellow, black, white, grey))

color_list_2:= list((pink, red, purple, brown))

color_list_3 = color_list_1

color_list_4 = list((pink, red, purple, brown))

print(color_list_1 is in color_list_3)

# The output is True

Code: Select all


print(color_list_2 == color_list_4))

# The output is True because of exact same content.

print(color_list_2 is in color_list_4)

# The output is False because they contain the same stuff but do not point to the same object.
 

POSTREACT(ions) SUMMARY

Post Reply