Using hasattr
This is a straightforward way but can be a bit hard to read.
Using isinstance
I prefer this method as it’s more readable.
Using try-except
This is another way, but it relies on exception handling. Unless there is a specific reason to use it, I wouldn’t choose it.