#Short hand and statement in an if statement
1 messages · Page 1 of 1 (latest)
It depends on how you code is made, can you share it?
Or is this purely theoretical?
With this snippet there's not much you can do to make this shorter.
Real quick, if you want to simplify this function you could separate some of the check in other method.
wdym by this
it's pretty self explanatory. You simply take your condition in your if and put it in a method that would return true or false depending on whether this condition is true or not.
sorry my english not very good
You know what a method is?
yes
You know that you can return boolean from method?
And a condition in a if needs a true or false?
class Something:
def __init__(self, ...):
self.data = ...
def has_data(self):
return self.data is not None
def check_click(self):
...
if self.has_data():
...
This is a simple example
ahhh ok. I think I understand.