#Short hand and statement in an if statement

1 messages · Page 1 of 1 (latest)

fiery plank
#

What is a shorthand way for checking that multiple variables are all equal to the same value in an 'if' statement if there is any// more efficient Thanks

whole vector
#

It depends on how you code is made, can you share it?

#

Or is this purely theoretical?

fiery plank
#

Ok i can

#

I'll share the part of the code

whole vector
#

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.

whole vector
#

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.

fiery plank
#

sorry my english not very good

whole vector
#

You know what a method is?

fiery plank
#

yes

whole vector
#

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

fiery plank
#

ahhh ok. I think I understand.