Skip to content
Advertisement

conditional expression in one line if statment

self.values is optional parameter (List) in my class.

I have the following code:

JavaScript

This produce

JavaScript

I know I can fix this by doing:

JavaScript

But isn’t there a shorter way to set it?

Advertisement

Answer

You can do the following, using the fact as it the list is None or empty, it’s evaluated as false and the other operand of the OR expression will be used

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement