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

    From Lawrence D'Oliveiro@21:1/5 to Paul Rubin on Sun Jun 23 07:13:26 2024
    On Sun, 23 Jun 2024 00:00:29 -0700, Paul Rubin wrote:

    Lawrence D'Oliveiro <[email protected]d> 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Lawrence D'Oliveiro on Sun Jun 23 00:00:29 2024
    Lawrence D'Oliveiro <[email protected]d> 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): ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Lawrence D'Oliveiro on Sun Jun 23 22:55:29 2024
    On Sun, 23 Jun 2024 01:17:35 -0000 (UTC), Lawrence D'Oliveiro wrote:

    Actually, both “and’ and “or” will work.

    No it won’t. It’ll fail in the case where one or the other arg is of an entirely different type.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)