• Python told me a Joke

    From Alan Bawden@alan@csail.mit.edu to comp.lang.python on Mon Sep 2 03:55:15 2024
    From Newsgroup: comp.lang.python

    Python 3.10.5 (v3.10.5:f37715, Jul 10 2022, 00:26:17) [GCC 4.9.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> x,_,z = [1,2,3]

    Works as expected.

    Now I didn't expect the following to work (but Python sometimes
    surprises me!), so I tried:

    >>> x,2,z = [1,2,3]
    File "<stdin>", line 1
    x,2,z = [1,2,3]
    ^^^^^^^^^^^
    SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

    Yeah, that makes sense, no surprises today... Except "maybe you meant
    '=='..." caught my attention. _Could_ that be what someone would want
    in this situation I wondered? So I tried:

    >>> x,2,z == [1,2,3]
    (1, 2, False)

    Now that made me laugh.

    - Alan

    [ Some people reading this will be tempted to explain what's really
    going on here -- it's not hard to understand. But please remember that
    a joke is never funny if you have to explain it. ]
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Mild Shock@janburse@fastmail.fm to comp.lang.python on Mon Sep 2 10:05:30 2024
    From Newsgroup: comp.lang.python

    You can try:

    1,2 == 2,2
    (1, True, 2)

    Its the same as:

    1, (2 == 2), 2
    (1, True, 2)

    Hope this helps!

    Alan Bawden schrieb:
    Python 3.10.5 (v3.10.5:f37715, Jul 10 2022, 00:26:17) [GCC 4.9.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> x,_,z = [1,2,3]

    Works as expected.

    Now I didn't expect the following to work (but Python sometimes
    surprises me!), so I tried:

    >>> x,2,z = [1,2,3]
    File "<stdin>", line 1
    x,2,z = [1,2,3]
    ^^^^^^^^^^^
    SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

    Yeah, that makes sense, no surprises today... Except "maybe you meant '=='..." caught my attention. _Could_ that be what someone would want
    in this situation I wondered? So I tried:

    >>> x,2,z == [1,2,3]
    (1, 2, False)

    Now that made me laugh.

    - Alan

    [ Some people reading this will be tempted to explain what's really
    going on here -- it's not hard to understand. But please remember that
    a joke is never funny if you have to explain it. ]


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Lawrence D'Oliveiro@ldo@nz.invalid to comp.lang.python on Mon Sep 2 22:01:52 2024
    From Newsgroup: comp.lang.python

    On Mon, 02 Sep 2024 03:55:15 -0400, Alan Bawden wrote:

    >>> x,2,z == [1,2,3]
    (1, 2, False)

    I wondered what was going on, until I realized that the three expressions making up the restult tuple are

    x
    2
    z == [1, 2, 3]

    [ Some people reading this will be tempted to explain what's really
    going on here -- it's not hard to understand. But please remember
    that a joke is never funny if you have to explain it. ]

    Damn. I always found it funny why I could never understand jokes. Now
    you’ve told me why, I can never feel that any more ...
    --- Synchronet 3.20a-Linux NewsLink 1.114