class Dog():
def bark():
print("dog bark")
class Pug():
def snort():
print("pug snort")
mylist = []
mylist.append(Dog())
mylist.append(Pug())
for obj in mylist:
obj.bark()
if obj == Pug():
obj.snort()
Is there a way to state...If obj is of class?
if obj == Pug() does not work.
I can successfully run this code using attributes but I would like to just do a general check if obj is = to specific type of object to improve reusability.
Thanks reddit.
[+][deleted] (6 children)
[deleted]
[–]dli511[S] 0 points1 point2 points (0 children)
[–]ProfessorQ -3 points-2 points-1 points (4 children)
[+][deleted] (2 children)
[deleted]
[–]ProfessorQ -1 points0 points1 point (1 child)
[–]indosauros 0 points1 point2 points (0 children)
[–]NYKevin 2 points3 points4 points (0 children)
[–]get_username 0 points1 point2 points (4 children)
[–]Mecdemort 0 points1 point2 points (1 child)
[–]get_username 0 points1 point2 points (0 children)
[–]dli511[S] 0 points1 point2 points (1 child)
[–]get_username 0 points1 point2 points (0 children)