Use THIS in #python instead of IF-ELSE!

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

Yes great example, i love the part where you overwrite the built in op that finds the bigger number. 😂

Randomize
Автор

You can use it inside of the print function: print(a if a > b else b)

insteresting
Автор

For those asking why not use max? First, any programmer should be able to find the max between 2 number without a library, second, anytime you call a function you are slowing everything down in a language not know to be fast to begin with.

LucasLocatelli
Автор

max(a, b) would solve your issue 😅 don't overwrite built-ins, that's bad and unexpected, your linting tool should warn you about that.

print(max(a, b))

if-else expression in python is bad for readability, other languages implement this in a more readable way: *a > b ? a : b*

hadawardgz
Автор

It has fewer lines and is more readable, but the disadvantage is that the branch coverage is likely to be missed when creating test cases.

s__r
Автор

You can use this code to
a=5
b=10
print(max(a, b))

Output:
>>> 10

princeprajapati
Автор

Think python is a bad language to show this. Syntax is unlike most other languages, where its even better readable (sentance != easy to read) I am btw. talking of this syntax (Java, C#, Js and more (i guess)): condition ? ValueIfTrue : ValueIfFalse)

Cyklon_
Автор

You can also use max Funktion so xou dont need a if elese

florian
Автор

Ya this is the ugliest version of a ternary operator. The ? : syntax is so much cleaner to read.

JDalmasca
Автор

All aspirin Devs, DO NOT DO THIS. PYTHON IS USED FOR READABILITY. UNLESS YOU DON'T WANT YOUR CODE TO BE READABLE, JUST DON'T

tinahalder
Автор

You overrode the max operator AND still used IF - ELSE 😂😂😂

Cristhiamification
Автор

Great tip.
A bit quiet video but the content makes up for it

BenRogersWPG
Автор

Reynald, please, just stop posting on this channel

krisz
Автор

I forgot this feature Thanks for telling again It's one line statement or something 😅

CC.unposted
Автор

instead of resorting to a ternary...

max = a
if (b > a):
max = b
print(max)

Better. It's not like we're running out of lines for our code to be in.

dusdnd
Автор

C/C++ and Java do this better with
v = cond ? True part : false
Part

dfields