Python 3 isinstance

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Jan 15 07:25:16 CET 2009


On Wed, 14 Jan 2009 22:03:37 -0500, Lambert, David W (S&T) wrote:

> Overly terse.  I do mean that this is illegal:
> 
> isinstance(s, {str, bytes})

*shrug*

Just change the {} to () and it will work fine.

Or do this:

isinstance(s, tuple({str, bytes}))

 
> tuples have order, immutability, and the possibility of repeat items.

Yes. And why is this a problem?


> A set is most reasonable in a mathematical sense.

What is the benefit of using sets instead of tuples inside isinstance?





-- 
Steven



More information about the Python-list mailing list