What is The Walrus Operator in Python?

What is The Walrus Operator in Python?

NeuralNine

2 года назад

14,025 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

PowerTopics
PowerTopics - 15.08.2023 13:37

Easy to understand

Ответить
X ZEX
X ZEX - 22.03.2023 19:19

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'

Ответить
Xtranger Nowrol Junkghip Wateril
Xtranger Nowrol Junkghip Wateril - 04.11.2022 21:31

You look like "TechWithTeam" channel but older 😹

Ответить
Dariusz Spiewak
Dariusz Spiewak - 26.10.2022 05:22

There are many more good uses for the walrus operator. Some of the uses can be found in James Powell's vids...

Ответить
Bob's Tap
Bob's Tap - 10.07.2022 09:04

Bro your examples was awesome! thanks

Ответить
Anacleta Ludovica
Anacleta Ludovica - 08.02.2022 07:32

The problem is that lines tends to get too long.

Ответить
Chad Gregory
Chad Gregory - 18.12.2021 22:12

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

Ответить
Nemoumbra
Nemoumbra - 27.11.2021 19:47

So this is basically a simple C++ assignment opeator, right?

Ответить
Lars
Lars - 16.11.2021 00:47

Amazing!

Ответить
Neuroszima
Neuroszima - 11.11.2021 12:21

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!

Ответить
Stepan Kolovorotnyy
Stepan Kolovorotnyy - 06.11.2021 05:20

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

Ответить
José Lara
José Lara - 02.11.2021 09:40

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

Ответить
THUNDER SKULL
THUNDER SKULL - 25.10.2021 13:46

Good video 📸 👍

Ответить
flex rhyme
flex rhyme - 19.10.2021 23:23

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.

Ответить
Henry Ash
Henry Ash - 19.10.2021 21:17

Epic

Ответить
Rodrigo Martín
Rodrigo Martín - 19.10.2021 00:03

are u lil supa?

Ответить
Recursive Triforce
Recursive Triforce - 18.10.2021 14:52

The most unknown is

A @ B

Ответить
mrmuranga
mrmuranga - 16.10.2021 20:49

would prefer readability for future sanity purposes..
good tutorial though..tks

Ответить
Zitron
Zitron - 16.10.2021 18:26

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.

Ответить
Gio
Gio - 16.10.2021 17:03

also known as an assignment expression, amazing stuff

Ответить
Mr. Beelzebub
Mr. Beelzebub - 16.10.2021 08:53

Always teaching new stuff thanks Man

Ответить
Aditya Pal
Aditya Pal - 16.10.2021 08:31

I've been using it for quite some time. This actually makes doing certain tasks easy.

Ответить
De Coder
De Coder - 16.10.2021 05:55

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

Ответить
Body&Soul Relaxing Music
Body&Soul Relaxing Music - 16.10.2021 03:31

Why are your other videos which are very important to us are not clear as this one?

Ответить
ThePaulCraft
ThePaulCraft - 16.10.2021 00:08

I think its a nice Idea to know, but its the opposite of a pure "function" in the context of functional programming.

Ответить
hailtotheking
hailtotheking - 15.10.2021 23:44

Another interesting use case might be if you do list comprehension in combination with slow rest requests for example.

Ответить
Thomas Goodwin
Thomas Goodwin - 15.10.2021 23:05

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.

Ответить
Zacky
Zacky - 15.10.2021 21:16

Wow this is very helpful specially for while loop. Thank you so much

Ответить
Mohd Mushtaq
Mohd Mushtaq - 15.10.2021 20:05

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

Ответить
Rasim Mammadov
Rasim Mammadov - 15.10.2021 18:49

Good Job!

Ответить
agou1980
agou1980 - 15.10.2021 17:54

In K&R C: while ((c = getchar()) != 'q')

Ответить
Adheesh • 2 seconds ago
Adheesh • 2 seconds ago - 15.10.2021 17:53

Luckily I knew abt that one.

Ответить
Turnaround
Turnaround - 15.10.2021 17:46

glad i knew this last two weeks ago.

Ответить
GiveMeTheTacos
GiveMeTheTacos - 15.10.2021 17:32

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.

Ответить
MANOJ 1234
MANOJ 1234 - 15.10.2021 17:16

Sir make a video on Google map clone from python.

Ответить
Ross
Ross - 15.10.2021 17:14

i remember reading about this when they added it and not understanding anything

Ответить
hwzzegwggs
hwzzegwggs - 15.10.2021 17:12

Nice I didn't even knew this one exists lol

Ответить