Python Forum

Full Version: how would you feel if ...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
how would you feel if Python's assignment operator was := instead of just = ?
(Apr-22-2021, 12:22 AM)Skaperen Wrote: [ -> ]how would you feel if Python's assignment operator was := instead of just = ?
Would have been incredibly silly change now as it has been = since the start.
As := was free added in Python 3.8(🐳rus operator)

>>> print(num = 99)
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: 'num' is an invalid keyword argument for print()

# Walrus power
>>> print(num := 99)
99
Saves us from calling len() twice.
lst = [1, 2, 3, 4]
if (n := len(lst)) > 3:
    print(f"List is too long <{n} elements,need to be <= 3>")
Output:
List is too long <4 elements,need to be <= 3>
i'm not asking in terms of a change, but rather, what if it had been that way since the beginning (e.g. would be silly to change it to =, now).
(Apr-22-2021, 12:22 AM)Skaperen Wrote: [ -> ]how would you feel if Python's assignment operator was := instead of just = ?

I won't feel any change, because of some relativistic effects during time travel.

I use from the IEC 61131-3 standard the Structured Text. The syntax is similar to Pascal, and it's not vendor-specific.
https://en.wikipedia.org/wiki/Structured_text
The:= is used for assignment. A plain colon is followed by a datatype and comparison is made with =.

I don't have bad feelings to write := and if Python had this instead of =, I think we won't recognize it or talk much about it.

Changing this decision afterwards without breaking all existing code is nearly impossible.
of course any change like that after it is established is, at best, a new language; entirely unsuitable for the previous.

but being one that dislikes typing := when i would need to type it a lot, i can say that the me in that universe where Python was created with := would likely not be coding in Python. i'm not sure what i would be using. maybe still doing Pike. but it seems to have stalled out, at least in this universe. in both cases there is still a little C.
I probably saved millions of times typing : with Python using = instead of :=! My main regret is that python uses . instead of just a space character. Using a space makes typing code much more fluid.
typing : involves hold Shift on qwerty keyboards. that is the big reason i dislike typing := many times.
Can't say it bothers me, having used it in Go and XQuery.
> Can't say it bothers me, having used it in Go and XQuery

i don't even know what those are? are they terminal emulators?
No, they're programming languages: https://golang.org/ and e.g. https://en.m.wikipedia.org/wiki/XQuery.
Pages: 1 2