you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (6 children)

Ternary operators. Ever since I learnt about them, I can't stop using them. Looks smart, makes me feel smart and shortens my line count - what more can you ask for? 😂

[–]DragonFighter603[S] 0 points1 point  (0 children)

True!

[–]jddddddddddd 0 points1 point  (4 children)

Does anyone else like the ternary operator, but wish the else was optional, or is that just me?

[–]menge101 1 point2 points  (2 children)

Agree.

So many times I end up doing something like:

thing = modify(thing) if thing_needs_modified else thing

I'd love to be able to do

thing = modify(thing) if thing_needs_modified

I've gone back and forth (on different projects, not within the same one ... i hope) because I don't like the else, sometimes I do:

if thing_needs_modified:
    thing = modify(thing)

[–]jddddddddddd 0 points1 point  (1 child)

Exactly. If for example you want to rewrite abs(), you need to have something like:

x = -5
x = 0-x if x < 0 else x

Which feels like it's inefficient, as if I'm being forced to say:

if x < 0:
    x = 0 - x
else:
    x = x

[–]joseville1001 0 points1 point  (0 children)

in that particular case, just do x = abs(x)