This repository was archived by the owner on Jul 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed
Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -155,7 +155,23 @@ be ``True`` if **both** are true.
155155 | ``False`` | ``True`` | ``False`` |
156156 +---------------+---------------+-----------------------------+
157157
158- .. todo: func_1() and func_2(); 0 and 5
158+ ``and`` operator work's not only with operands of Boolean type.
159+ It's behavior:
160+
161+ - evaluate 1st operand; return it, if it's ``False`` and finish
162+ - evaluate 2nd operand; return it, if it's ``False`` and finish
163+ - return 2nd operand
164+
165+ .. code-block:: python
166+
167+ >>> 1 and 5
168+ 5
169+ >>> '' and None
170+ ''
171+ >>> 0 and True
172+ 0
173+ >>> 5 and False
174+ False
159175
160176Getting started with ``or`` operator
161177------------------------------------
@@ -181,7 +197,23 @@ then the expression is ``False``.
181197 | ``False`` | ``True`` | ``True`` |
182198 +---------------+---------------+----------------------------+
183199
184- .. todo: default mutable value, e.g. x = x or []
200+ ``or`` operator work's not only with operands of Boolean type.
201+ It's behavior:
202+
203+ - evaluate 1st operand; return it, if it's ``True`` and finish
204+ - evaluate 2nd operand; return it, if it's ``True`` and finish
205+ - return 2nd operand
206+
207+ .. code-block:: python
208+
209+ >>> 42 or True
210+ 42
211+ >>> None or []
212+ []
213+ >>> 0 or True
214+ True
215+ >>> [[]] or ''
216+ [[]]
185217
186218Comparison
187219==========
You can’t perform that action at this time.
0 commit comments