Є !=(не рівний) оператор, який повертається, Trueколи два значення відрізняються, хоча будьте обережні з типами, оскільки "1" != 1. Це завжди поверне True та "1" == 1завжди поверне False, оскільки типи відрізняються. Python динамічно, але сильно набраний, а інші статично набрані мови будуть скаржитися на порівняння різних типів.
Також є elseпункт:
# This will always print either "hi" or "no hi" unless something unforeseen happens.
if hi == "hi": # The variable hi is being compared to the string "hi", strings are immutable in Python, so you could use the 'is' operator.
print "hi" # If indeed it is the string "hi" then print "hi"
else: # hi and "hi" are not the same
print "no hi"
isОператор є ідентифікатор об'єкта оператор використовується для перевірки , якщо два об'єкти практично однаковий:
a = [1, 2]
b = [1, 2]
print a == b # This will print True since they have the same values
print a is b # This will print False since they are different objects.
else,!=(необов'язково<>) абоis not?