Sujet : Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited) De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro) Groupes :comp.lang.python Date : 23. Jun 2024, 02:17:35 Autres entêtes Organisation : A noiseless patient Spider Message-ID :<v57t3f$tpf$1@dont-email.me> User-Agent : Pan/0.158 (Avdiivka; )
Consider a function taking two args “a” and “b”, which can be of str, bytes or bytearray type, just so long as both are of the same type. One easy way to test this is
if sum(isinstance(a, t) and isinstance(b, t) for t in (str, bytes, bytearray)) != 1 : raise TypeError("args must both be str or bytes") #end if
Actually, both “and’ and “or” will work.
Date
Sujet
#
Auteur
23 Jun 24
Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)