Python Forum
how would you feel if ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how would you feel if ...
#1
how would you feel if Python's assignment operator was := instead of just = ?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
(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>
buran and Gribouillis like this post
Reply
#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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(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.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
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.
Skaperen likes this post
Reply
#7
typing : involves hold Shift on qwerty keyboards. that is the big reason i dislike typing := many times.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
Can't say it bothers me, having used it in Go and XQuery.
Reply
#9
> 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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#10
No, they're programming languages: https://golang.org/ and e.g. https://en.m.wikipedia.org/wiki/XQuery.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020