Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)

Liste des GroupesRevenir à cl python 
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.python
Date : 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.

Date Sujet#  Auteur
23 Jun 24 * Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)5Lawrence D'Oliveiro
23 Jun 24 +- Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)1Keith Thompson
23 Jun 24 +* Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)2Paul Rubin
23 Jun 24 i`- Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
24 Jun 24 `- Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal