Existe el !=operador (no igual) que regresa Truecuando dos valores difieren, aunque tenga cuidado con los tipos porque "1" != 1. Esto siempre devolverá True y "1" == 1siempre devolverá False, ya que los tipos difieren. Python es dinámicamente, pero fuertemente tipado, y otros lenguajes estáticamente tipados se quejarían de comparar diferentes tipos.
También está la elsecláusula:
# 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"
El isoperador es el operador de identidad de objeto utilizado para verificar si dos objetos son iguales:
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,!=(opcionalmente<>) ois not?