Discussion:
Python told me a Joke
(too old to reply)
Alan Bawden
2024-09-02 07:55:15 UTC
Permalink
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
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
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. ]
Mild Shock
2024-09-02 08:05:30 UTC
Permalink
Post by Alan Bawden
1,2 == 2,2
(1, True, 2)
Post by Alan Bawden
1, (2 == 2), 2
(1, True, 2)

Hope this helps!
Post by Alan Bawden
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
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
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. ]
Lawrence D'Oliveiro
2024-09-02 22:01:52 UTC
Permalink
Post by Alan Bawden
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]
Post by Alan Bawden
[ 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 ...

Loading...