Комментарии:
What do you guys think of this new feature? Can you see yourself using it? Let me know !!
Ответитьthanks ,please explain python 3.10 updates too
Ответитьcool video
Ответитьdoes anyone explain better than him()?
ОтветитьIt would be better if you had run all the codes. Very bad tutorial. Walrus is already unreadable and your tutorial makes it more difficult to understand by not providing the output
ОтветитьThey should have made it into a proper function SET(a,b) where B is an expression, A is a lvalue (variable) and SET a function which returns B. It would have been a whole lot clearer and properly wouldn't have caused that much controversy. It's a function. It's not an operator like +, -, etc. since what does 1 := 5 mean? What does it return? 5?
Added bonus:
a = SET(b, 5+3) or in C a = b = 5+3;
import this
ОтветитьI think the walrus operator isn't too beginner-friendly but yeah you can use it if you want and i think w'all must use it
ОтветитьI don't understand why people are spreading hate towards the walrus operator! Its an amazing operator which makes our lives easier. Sometimes this world is to hard to comprehend
ОтветитьI'm not a Python dev but i'm trying to understand why this is a big deal. Is this like the await keyword in JS?
ОтветитьLate to the party here but I dont understand why people are angry over this feature, i think its really elegant and so many times i wished i could do what C or C++ could in Python and now i can without repeating myself awkwardly
ОтветитьDoes variable of walrus operator is removed after loop?
Ответитьhow do install that version of python???
ОтветитьWe need egg man operators...
ОтветитьI can see why this could be controversial, but I kind of dig it. I can definitely see the usefulness
ОтветитьI feel like there’s a random pascal fan at Python HQ. walrus was originally used as all-purpose assignment in the advent of high level programming languages. C essentially reversed that trend by replacing it with just “=“, and marking the ‘equals to binary operator’ be “==“. A part of me wonders if they’re adding walrus to add specific precedence, but that would imply to me there’s some brick wall with interpreting python code (with inline assignment), so they added a new operator. Maybe readability is the long term goal? Something’s off about the decision to add this.
ОтветитьYou're highlighting the silliest feature of 3.8. If you want to look at something truly impactful to Python, check out multiprocessing.shared_memory.
ОтветитьPersonally, I love it. It makes things less clumsy.
ОтветитьWalrus? Why not Zoidburg? :=
ОтветитьUsing a Pascal operator in a C based language to help avoid confusing programmers with complicated things like syntax and logic. It seems like increasing the confusion instead. Kudos, Python.
ОтветитьBad programmers think about syntax. Good programmers think about data structures.
ОтветитьSTUPID
Ответитьi got a python 7.8 inches in my pants.... once you get laid youll forget all about this python bs
ОтветитьI. Love it.
practical, pythonic, elegant solution, easy to read.
gonna move up to 3.8.1 then
What about speed? Is it faster?
ОтветитьLooks interesting
Ответитьlol why though
ОтветитьLess lines of code doesn’t always make it more readable. It might be worth it in the case where you would have the same action before and inside the while loop, but aside from that you’re probably better off doing it the normal way.
ОтветитьSo syntactical sugar which may be neat but definitely is less readable.
Ответитьif there is not actual difference in terms of performance and optimization, I guess is still preferable to use the more readable solution, right?
Ответитьso basically assignments return the value of the assignment .. just like in C :-)
i don't really know why this is not default-behavior
Can you talk about the PEP recommendations for walrus operators? Feel like a lot of the criticism is due to readability.
Ответитьlong lines ahead
ОтветитьIt probably doesn't work this way, but I would probably use it more if the variable was local only to the indented part.
ОтветитьGreat. In go := is "Short variable declaration". Gonna make switch between Go and Python even more confusing ...
ОтветитьSo now we have a mixture of = in assignment statements and := in assignment expressions (which are a bit less powerful). And other uses of = for non-assignments (like named parameters).
C-based languages have just one syntax for assignments (=), as expressions which also can be used in statement positions. But that was not possible in Python, as = was used in different contexts already.
Is there a performance compromise and using the new walrus functionality?
ОтветитьI am confused why is it controversial. I've been using such construct in C++ for quite a while:
if (auto *ptr = some_factory) do_stuff;
and I never had problems with readability. But I guess there are still people who would write:
If (statement)
return true;
else
return false;
Instead of:
return statement;
Really cool feature! I actually immediately had ideas where i could have used it in the past few weeks
ОтветитьI argued for just evaluating the operations first before compare, that is if (n = len(a)) > 10 would be valid. The choice of := is rather messy. I might use it, but I really don't like the syntax souce to avoid ambiguity.
ОтветитьI am new to python and code. So, I could see myself using the walrus. Koo koo katchoo
ОтветитьThis looks really useful in list, etc comprehension too for testing/returning a value in the filter section etc
ОтветитьThe while expression always felt broken in Python without the ability to assign a value in the condition. The walrus is a little silly because you could just as easily enforce putting parentheses around the assignment which makes it pretty obvious what you're doing, but ... maybe that just felt wrong to people because I guess requiring parenthesis is sorta non-Pythonic unless you're using tuples. Whatever. I think they just like to make Python quirky.
ОтветитьUnisys MCP Algol has had this operator since forever, I first used it in 1983.
ОтветитьIt’s interesting, and I can see why I might find it controversial - the code is shorter, and more compact but maybe at the cost of being slightly less readable. There’s almost a reverse Polish notation sense with the parens and how the line is read by a human.
However - I run into this situation often enough where I need to a) evaluate an expression b) test the expression result against a condition and c) use the expression result in subsequent code. I hate writing even mildly complex expressions more than once, so I often will relegate it to a new function so that b and c call foo() to get the value - DRY. That still means the operation has to run twice, or I have to implement some kind of variable cache (in the rare case the op is expensive).
I’ll probably find uses for it, sparingly. I hate unreadable code more than repetitive code. The latter can be refactored, the former is a nightmare to decipher.
your 3rd example is bad, in the no walrus example you set ans to the input value, while in the walrus example you set it a boolean.
ОтветитьI’m not sure if I approve of this…
ОтветитьVisual Basic has this operator
ОтветитьSimilar to lambda functions, I find code written like this difficult to read. Sure, there are use-cases, but I certainly wouldn't default to sprinkling walrus operations throughout my code.
Ответить