Checking for Inequality in Python
There is also an operator != which tests for inequality.
Let there be a variable:
pythontst = 5
Let's check that it is not equal to 0:
pythonif tst != 0:
print('+++') # this will work because the variable is NOT equal to 0
else:
print('---')
Now let's change the value of the variable:
pythontst = 0
if tst != 0:
print('+++')
else:
print('---') # this will work because the variable is equal to 0
Задание 1
Given a variable:
pythontst = -4
Check that it is not equal to 4.
Задание 2
The following code is given:
pythontst = 123
if tst != 123:
print('+++')
else:
print('---')
Tell me what will be output to the console.
Задание 3
The following code is given:
pythontst = ['a', 'b', 'c']
if tst[1] != 'c':
print('+++')
else:
print('---')
Tell me what will be output to the console.
Задание 4
The following code is given:
pythontst1 = [3, 4, 5, 6]
tst2 = list('3456')
if tst1 != tst2:
print('+++')
else:
print('---')
Tell me what will be output to the console.