For example: I have a list called container
. In it are some elements and I want to check if eg. any of them are complex.
container = [1, 0.5, "text", 1j]
if isinstance(container[?], complex):
print("This list has complex elements")
In this example, I could've written container[-1]
, but is there an universal method?
I could use a for loop, but I'm wondering if there are better ways to do this.