Skip to content

Instantly share code, notes, and snippets.

@calthoff
Created December 3, 2019 02:08
Show Gist options
  • Save calthoff/104bb758e001df4b4a5eb643bc5d0a20 to your computer and use it in GitHub Desktop.
Save calthoff/104bb758e001df4b4a5eb643bc5d0a20 to your computer and use it in GitHub Desktop.
# Exercise 1 Solution
class Square:
square_list = []
def __init__(self):
self.square_list.append(self)
# Exercise 2 Solution
class Square:
def __init__(self, s1):
self.s1 = s1
def calculate_perimeter(self):
return self.s1 * 4
def __repr__(self):
return "{} by {} by {} by {}".format(self.s1, self.s1, self.s1, self.s1)
# Exercise 3 Solution
def same(obj1, obj2):
return obj1 is obj2
class Square:
def __init__(self):
pass
@MustafaKhurram2k4
Copy link

MustafaKhurram2k4 commented Jan 18, 2024

def are_same_object(obj1, obj2):
return obj1 is obj2

obj_a = [1, 2, 3]
obj_b = [1, 2, 3]
obj_c = obj_a

print(are_same_object(obj_a, obj_b)) # Output: False
print(are_same_object(obj_a, obj_c)) # Output: True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment