Sujet : Re: 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.pythonDate : 23. Jun 2024, 09:13:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v58hum$7vgu$1@dont-email.me>
References : 1 2
User-Agent : Pan/0.158 (Avdiivka; )
On Sun, 23 Jun 2024 00:00:29 -0700, Paul Rubin wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
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 type(a)==type(b) and type(a) in (str, bytes, bytearray): ...
Better to use isinstance instead of direct type comparison.