Python Forum
how would you feel if ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how would you feel if ...
#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>
Gribouillis and buran like this post
Reply


Messages In This Thread
how would you feel if ... - by Skaperen - Apr-22-2021, 12:22 AM
RE: how would you feel if ... - by snippsat - Apr-22-2021, 02:50 AM
RE: how would you feel if ... - by Skaperen - Apr-23-2021, 06:03 PM
RE: how would you feel if ... - by DeaD_EyE - Apr-24-2021, 09:13 AM
RE: how would you feel if ... - by nilamo - May-07-2021, 06:23 PM
RE: how would you feel if ... - by Skaperen - Apr-25-2021, 06:03 PM
RE: how would you feel if ... - by Gribouillis - Apr-26-2021, 09:19 AM
RE: how would you feel if ... - by Skaperen - Apr-26-2021, 10:27 PM
RE: how would you feel if ... - by ndc85430 - Apr-29-2021, 05:06 PM
RE: how would you feel if ... - by Skaperen - Apr-30-2021, 01:04 AM
RE: how would you feel if ... - by ndc85430 - May-02-2021, 04:54 AM
RE: how would you feel if ... - by Skaperen - May-03-2021, 07:40 PM
RE: how would you feel if ... - by Larz60+ - May-07-2021, 11:00 PM
RE: how would you feel if ... - by Skaperen - May-10-2021, 02:14 AM
RE: how would you feel if ... - by xMaxrayx - May-16-2024, 04:45 PM
RE: how would you feel if ... - by Skaperen - May-18-2024, 06:02 PM

Forum Jump:

User Panel Messages

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