⊗pyPmCdLA 131 of 208 menu

Logical AND in Python

Sometimes it may be necessary to compose a complex condition. For this, you can use the operator and (logical И), which specifies the simultaneity of conditions.

Let us have a variable tst:

tst = 5

Let's check if it is greater than zero and at the same time less than 10:

if tst > 0 and tst < 10: print('+++') else: print('---')

Conditions can be imposed not on one variable, but on different ones. Let's create a condition that must be satisfied if the variable tst1 is equal to 2 and simultaneously if the variable tst2 is equal to 3:

tst1 = 2 tst2 = 3 if tst1 == 2 and tst2 == 3: print('+++') else: print('---')

Given a variable:

tst = -3

Check that it is greater than zero and less than 5.

Given a variable:

tst = 21

Check that it is greater than or equal to 10 and less than or equal to 20.

Two variables are given:

tst1 = 6 tst2 = 10

Check that the first variable is less than 8 and the second is greater than or equal to 10.

The following code is given:

tst1 = 'abcde' tst2 = list(tst1) if len(tst1) >= 5 & len(tst2) < 8: print('+++') else: print('---')

Tell me what will be output to the console.

byenru