Answer the question
In order to leave comments, you need to log in
What is the difference between 'AND' and '&'?
Worked with Pandas.
And when I tried to enter, for example, such a condition
a=data[(data.Age > 20) and (data.Wage > 10)]. count()
a=data[(data.Age > 20) & (data.Wage > 10)]. count()
False and True
False
255 & 1
1
Answer the question
In order to leave comments, you need to log in
the difference is that `and` is a logical operation, it cannot be overridden, that is, it is impossible for an object to implement a method that will implement its own algorithm for calculating the result of the operation.
This is due to the standard optimizations of logical expressions, which (optimizations) are in almost all languages.
Roughly speaking, the `and` operator (conjunction) takes two arguments (left and right) and returns the value of the first false or the last true, if all are true.
For example:
'one' and 0 # вернёт 0
'' and 13 # вернёт ''
3 and 5 # вернёт 5
3 or 5 # вернёт 3
'' or 'hello' # вернёт 'hello'
None or 0 # вернёт 0
Class MyClass:
def __and__(self, right_argument):
result = 'что угодно'
print(f'Фигасе: {self} & {right_argument} -> {result}')
return result
a = MyClass()
b = MyClass()
print('Вот так вот:\n', a & b)
Фигасе: <__main__.MyClass object at 0x7f3df1aeb588> & <__main__.MyClass object at 0x7f3df1aeb438> -> что угодно
Вот так вот:
что угодно
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question