isinstance()

Chris Angelico rosuav at gmail.com
Fri Aug 4 19:39:16 EDT 2023


On Sat, 5 Aug 2023 at 09:36, dn via Python-list <python-list at python.org> wrote:
> Faced with a situation where an argument may be a scalar-value or an
> iterable, I'll presume the latter, eg throw it straight into a for-loop.
> If that fails (because the argument is a scalar), use try-except to
> re-route the logic.

That's great as long as you aren't expecting to handle strings. The
string "spam" is sometimes equivalent to the list ["s", "p", "a", "m"]
and sometimes not.

ChrisA


More information about the Python-list mailing list