Hidden Python operator that will make your code 3x shorter

preview_player
Показать описание
#python #programming #coding #codinglife
Рекомендации по теме
Комментарии
Автор

It's not easy to read. I won't use it even if I am comfortable with it. My code must be readable by other devs.

elfyjohnson
Автор

While loops are always easier for audits, depends on if anyone is suppsoed to read it or not

DreadHalfling
Автор

great way to introduce bugs and confusion in code.

WalterBoring
Автор

It really reminds me of list comprehension, but for the case of "will I use it" not likely but it's awesome thanks for sharing this.

MichealOshionya-qjrc
Автор

Very cool til. First time I'm seeing a use case for walrus operator. Could you make another short showing other useful use case of it?

EnglishRain
Автор

You are the first to describe what I am dealing with right now. It is aboiut a job offer. It relates to past things and it is probably my Q to surrender to this reality right now. And to value myself. 😊

BrandyWiseNL
Автор

if your coming from a C/C++ background its easy to understand. but those who aren't could be more difficult. in C its common to do stuff like ths
FILE *fp = NULL;
char buffer[255];
if ( (fp = fopen( file, "w") != NULL )
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
printf("Read: %s", buffer);
}

dfields
Автор

I didn’t know that was called Walrus. I see it now lol. Literally looks like a lil Walrus and he so cute! (:= he is watching your every move.

brycesakal
Автор

I will use this, but to help other devs, ill leave the original loop in comment form so they'll understand, while the code is functional

SmoothSmellsWithT
Автор

the more I think I know python the more I keep getting recommended your videos and realizing I didn't even know half of these things existed in the first place

pxrrtt
Автор

Actually, i used this function for running a neural network. I ran the model endlessly until i get the result i need😂

faruqakmal
Автор

it's definitely not easy to understand if not in the know, but isn't that why we comment our code.

trevorevans
Автор

Code readability goes must be prioritized before this kind of expressions. It doesn't matter you know this. It shouldn't be used.

enriquegato
Автор

For so long, I have been looking for a way to achieve this in Python as I could already do it in C. It makes writing code way faster and more efficient, but can only be understood by advanced C programmers. Thanks for the tip Tim!
Keep it coming!

johneric
Автор

This is great but most devs want to see that if/else. I’d use it but not so much.

Jhn.R
Автор

I'm not a python programmer, I am a c programmer, but I do essentially separate my code into more lines to make things easily to read

colinmaharaj
Автор

Thank you but as a beginner😅 i prefer the first code .

amirmohamed
Автор

oh wow.. I did not know about that. What happens if the warlus operator defines a variable and at the end of the function it is not defined and you return the variable at the end of your function? Will you get undefined or will it actually return a None value?

oj
Автор

The second option continues to allocate memory, non-sense IMHO

StudioTopWebErriquez
Автор

Readability > conciseness.
If you prioritise compressing a very easy to read 10 line flow into some magic mumbo jumbo 1 inline expression that makes the flow harder to understand youre not really a good dev

vanamutt