What is The Walrus Operator in Python?

  Рет қаралды 14,235

NeuralNine

NeuralNine

Күн бұрын

Пікірлер: 56
@joselara7851
@joselara7851 3 жыл бұрын
The example with list comprehension was nice, I always wondered if this was possible without calling the same function twice, I will use it for sure
@hwzzegwggs8029
@hwzzegwggs8029 3 жыл бұрын
Nice I didn't even knew this one exists lol
@NeuralNine
@NeuralNine 3 жыл бұрын
Now you know! :)
@hwzzegwggs8029
@hwzzegwggs8029 3 жыл бұрын
@@NeuralNine yeah ty
@pokerchannel6991
@pokerchannel6991 20 күн бұрын
in your last example, I put in a sleep function of 2 second and that would simulate a long call. the speed difference is massive
@GiveMeTheTacos
@GiveMeTheTacos 3 жыл бұрын
I saw the walrus operator in the wild a few weeks ago and I couldn't find a decent explanation of its purpose in Python. I was pretty pumped when I saw this video pop up in my feed.
@NeuralNine
@NeuralNine 3 жыл бұрын
Happy to help! ^^
@skloit_dev3089
@skloit_dev3089 3 жыл бұрын
Same
@chadgregory9037
@chadgregory9037 2 жыл бұрын
its almost like.... google knew what to recommend to you =]
@bob_pm
@bob_pm 2 жыл бұрын
Bro your examples was awesome! thanks
@xzex2609
@xzex2609 Жыл бұрын
in the first example if you did not use () between the walrus and the non equality operator then the lower priority of the walrus operator would cause a problem. you can not use command := input() != 'q' ; unless (command := input) != 'q'
@salarghaffarian4914
@salarghaffarian4914 11 ай бұрын
Thanks for the great content!
@chadgregory9037
@chadgregory9037 2 жыл бұрын
Is this potentially something that a compiler could "figure out" at run time, and "optimize" what actually gets run toward the more efficient method of doing it? Idk the formal words to use, I just know I've seen comparisons between python and C, and shown that certain things written in python that might look "not optimal" is actually interpreted by the compiler at run time and "figured out" and "made" more efficient by using the "actual" best method that should/could have been used
@adityapal7764
@adityapal7764 3 жыл бұрын
I've been using it for quite some time. This actually makes doing certain tasks easy.
@education.online_frevryone
@education.online_frevryone Жыл бұрын
Easy to understand
@mr.beelzebub888
@mr.beelzebub888 3 жыл бұрын
Always teaching new stuff thanks Man
@anonlegion9096
@anonlegion9096 3 жыл бұрын
also known as an assignment expression, amazing stuff
@stepan_chous
@stepan_chous 3 жыл бұрын
As for the last example, doesn’t Python interpreter optimise it automatically? As far as i know in C if you call function with the same argument for a few times its result is kept in memory. This optimisation is made by compiler
@obed818
@obed818 2 жыл бұрын
You are actually right, even though i dont get why when i try simple code it id about always faster with walrus, but i think C only store hashable value although im not 100% sure
@zacky7862
@zacky7862 3 жыл бұрын
Wow this is very helpful specially for while loop. Thank you so much
@pokerchannel6991
@pokerchannel6991 19 күн бұрын
walrus hype!
@MANOJ-fz4ku
@MANOJ-fz4ku 3 жыл бұрын
Sir make a video on Google map clone from python.
@decoder6878
@decoder6878 3 жыл бұрын
Awesome tutorial I have seen some code with colon in the function. def my_func(int : something): pass If possible please make a video on what this is and how it works. Thanks
@goldenaxe2924
@goldenaxe2924 3 жыл бұрын
its called type-hinting, meant to show the person using the function what type should be passed in
@decoder6878
@decoder6878 3 жыл бұрын
@@goldenaxe2924Thank you. I'll look up for more info on type hinting.😊
@dariuszspiewak5624
@dariuszspiewak5624 2 жыл бұрын
There are many more good uses for the walrus operator. Some of the uses can be found in James Powell's vids...
@larsbro
@larsbro 2 жыл бұрын
Amazing!
@mbox1510
@mbox1510 3 жыл бұрын
Another interesting use case might be if you do list comprehension in combination with slow rest requests for example.
@nemoumbra0
@nemoumbra0 2 жыл бұрын
So this is basically a simple C++ assignment opeator, right?
@thunderskull258
@thunderskull258 3 жыл бұрын
Good video 📸 👍
@thomasgoodwin2648
@thomasgoodwin2648 3 жыл бұрын
Guido von Rossum quit his gig as THE Python guy over the walrus operator. Not so much the operator itself as much as the bitter fighting that erupted over it's inclusion. Part of the argument was that if == vs = could cause problems, imagine what kind of trouble you could get in with accidental assignments when you really just wanted a boolean result. There were many in the community that felt non explicit assignments were as evil as the reviled 'Goto'. Sorry I had to use language like that here, but sometimes just have to man up and know there were in the past forms of code worse than Stalin, Mao, and Hitler combined. Funny thing is, the same peeps that loved goto hated recursion. Having a subroutine call itself was considered extremely naughty back in the day.
@Neuroszima
@Neuroszima 2 жыл бұрын
really hard to belive, as for example, quicksort being a 1959 sorting algorithm, is based on recursion
@thomasgoodwin2648
@thomasgoodwin2648 2 жыл бұрын
@@Neuroszima Yes, it is hard to believe. But it is true. The old line was : it's good for solving Towers of Hanoi and that's IT! Don't ever do this, Bad, Bad, Bad! Since then it has become an entire paradigm. Funny thing is, personally, I hate functional programming.
@RecursiveTriforce
@RecursiveTriforce 3 жыл бұрын
The most unknown is A @ B
@BanHelsing
@BanHelsing 3 жыл бұрын
i remember reading about this when they added it and not understanding anything
@NeuralNine
@NeuralNine 3 жыл бұрын
Now you understand it hopefully! ^^
@Bsoul_music
@Bsoul_music 3 жыл бұрын
Why are your other videos which are very important to us are not clear as this one?
@rasimatics
@rasimatics 3 жыл бұрын
Good Job!
@thepaulcraft957
@thepaulcraft957 3 жыл бұрын
I think its a nice Idea to know, but its the opposite of a pure "function" in the context of functional programming.
@mrmuranga
@mrmuranga 3 жыл бұрын
would prefer readability for future sanity purposes.. good tutorial though..tks
@Zitronbtw
@Zitronbtw 3 жыл бұрын
TIL the Walrus Operator is called the Walrus Operator because it looks like a Walrus. Literally had no idea what it's purpose was until this video.
@xtrangernowroljunkghipwate659
@xtrangernowroljunkghipwate659 Жыл бұрын
You look like "TechWithTeam" channel but older 😹
@adheesh2secondsago630
@adheesh2secondsago630 3 жыл бұрын
Luckily I knew abt that one.
@tincho15neem
@tincho15neem 2 жыл бұрын
The problem is that lines tends to get too long.
@programminghero432
@programminghero432 3 жыл бұрын
hello sir I want to create a ml+ai bot that operates a small machine to operate that machine it will learn from the videos ,but the problem is that how should I make it learn from the videos
@anonlegion9096
@anonlegion9096 3 жыл бұрын
lol thats not how machine learning works
@programminghero432
@programminghero432 3 жыл бұрын
@@anonlegion9096 bro long ago internet was not expected to create a suitable means of communication but still we got a breakthrough so I hope there will be a way to get it done
@anonlegion9096
@anonlegion9096 3 жыл бұрын
@@programminghero432 What?? Can you even tell me what kind of machine learning model your brilliant idea would be? Classification? Regression? What?
@programminghero432
@programminghero432 3 жыл бұрын
@@anonlegion9096 I dont know that's why I am asking to get some clues
@henryash413
@henryash413 3 жыл бұрын
Epic
@flexrhyme4155
@flexrhyme4155 3 жыл бұрын
Yo I just downloaded python 3.10.0 and I don't have any of the things you have. Like the side bar and the top bar. Is there something i need to set up to get those? I only have the black command console.
@Neuroszima
@Neuroszima 2 жыл бұрын
don't tell me this is something that very little people know about, i have waited for this operator to be added in one of the languages since i programmed in Pascal!
@rodrigomartin5543
@rodrigomartin5543 3 жыл бұрын
are u lil supa?
The Python Walrus Operator is Awesome!
13:41
k0nze
Рет қаралды 1 М.
Make Your Python Code More Professional
19:43
NeuralNine
Рет қаралды 66 М.
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 39 МЛН
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 77 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 102 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,6 МЛН
5 Really Cool Python Functions
19:58
Indently
Рет қаралды 64 М.
What is Python's Main Function Useful For?
8:08
NeuralNine
Рет қаралды 79 М.
Python's assignment expression ("walrus") operator: What, why, and how
12:55
Python and Pandas with Reuven Lerner
Рет қаралды 1,2 М.
Walrus operator in Python | Grant Sanderson and Lex Fridman
4:00
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 409 М.
A Walrus Meets a Python - What is the := Walrus Operator?
16:35
Michael Kennedy
Рет қаралды 3,2 М.
Python's most DISLIKED __dunder__ (and what to use instead)
9:59
The most controversial Python feature | Walrus operator
8:08
Lex Fridman
Рет қаралды 400 М.
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 39 МЛН