Can anybody tell me what I’m doing wrong here, please?
Link to the lesson
Screenshot
Instructions
For every element
in can_we_count_it
, check if the element has the attribute .count
using the hasattr()
function. If so, print the following line of code:
print(str(type(element)) + " has the count attribute!")
Code
can_we_count_it = [{'s': False}, "sassafrass", 18, ["a", "c", "s", "d", "s"]]
for element in can_we_count_it:
if hasattr(element, 'count'):
print(f"{element} has the count attribute!")