ScanSkill

and

This and operator returns the first operand that evaluates to False or the last one if all are True.

Syntax

A and B

Here,

  • A: Required. Any valid object.
  • B: Required. Any valid object.

Note: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets, and frozensets), these all are interpreted as False. And the rest of the others are interpreted as True.

Examples

>>> x and y

Here, first, x is evaluated; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.

>>> 0 and '' and False
0
>>> 1 and '' and False
''
>>> 1 and 'A' and False
False
>>> 1 and 2 and 3
3
>>> b = '' and 'ABCD'
>>> b
''
>>> b = 0 and 1
>>> b
0
  • In conditional statements

Return True if both statements are True, otherwise it will return False.

>>> if 13 > 7 and 13 < 10;
...     print("Both are True.")
... else:
...     print("One of the statements is False.")
...
'One of the statements is False.'