Python básico linux
#ejemplo_operadores_python
Crea un archivo .py con el siguiente contenido (hazlo ejecutable ) y mira el resultado
#!/usr/bin/python
# Declaramos variables
a = 5
b = 10
c = 3
d = "Hola"
# Operadores aritmeticos
#se hace el "calculo" y se guarda en una variable
e = a+b
f = b/a
g = b%c
h = b//c
i = a**2
print( e, f, g, h, i ) # Resultado 15 2.0 1 3 25
#Operadores de comparacion
print( d == "Hola" ) # Devuelve True
print( d == "hola" ) # Devuelve False
print( d != "hola" ) # Devuelve True
print( a < b ) # Devuelve True
print( a > c ) # Devuelve True
print( a == b ) # Devuelve False
#operadores logicos
print ( a < b and c < a ) # Cumple ambas condiciones, devuelve True
print( a < b and c > a ) # Cumple una condicion, devuelve False
print( a > b or c < a ) # Cumple una condicion, devuelve True
print ( not a < b ) # Cumple la condicion, es True pero invierte a False
1 · 292 ·