Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/marioaje/Python/llms.txt

Use this file to discover all available pages before exploring further.

Operators are the symbols that tell Python what to do with your values. Whether you are adding two numbers, checking whether a password matches, or deciding if two conditions are both true at the same time, operators are the building blocks of every expression in the language. This page walks through the three operator families you will meet in Week 1: arithmetic, comparison, and logical.

Section 1 — Arithmetic Operators

The course introduces arithmetic operators through a practical program that asks the user to type values at the keyboard and then adds them together. This teaches two important skills at once: capturing user input with input() and converting that input from a string to a number with int().
semana1/operaciones.py
#captura el valor del teclado
#y lo asigna a una variable en este caso se
#llama dato1
dato1 = input("Ingresa cualquier valor1: ")
dato2 = input("Ingresa cualquier valor2: ")
dato3 = int(input("Ingresa cualquier valor3: "))
#hablo acerca de lenguage no tipado
dato1= int(dato1)
dato2= int(dato2)

resultado = dato1 + dato2 + dato3

print("El usuario ingreso:", resultado)
input() always returns a string, even when the user types a number. Before you can do maths with it you must convert it: int(dato1) turns the string "30" into the integer 30. You can do the conversion on the same line as the input call — dato3 = int(input("...")) — or in a separate step, as shown for dato1 and dato2 above.

The Four Arithmetic Operators

The course exercise asks you to implement all four operations. Here is what each one looks like, using the variables from the program above:
OperatorNameExampleResult
+Additionvariablea + variableb45
-Subtractionvariablea - variableb15
*Multiplicationvariablea * variableb450
/Divisionvariablea / variableb2.0
The commented-out lines in the original file show how the instructor first demonstrated addition and subtraction with fixed values before moving on to input():
semana1/operaciones.py (commented examples)
#30 manzanas + 15 manzanas
# variablea = 30
# variableb = 15
# resultado = variablea + variableb
# print( "La suma de", variablea, "+", variableb, "=" ,resultado, "manzanas" )

# resultado = variablea - variableb
# print( "La resta de", variablea, "-", variableb, "=" ,resultado, "manzanas" )

Section 2 — Comparison Operators

Comparison operators evaluate a relationship between two values and always return a boolean (True or False). They are most useful inside if statements and logical expressions.
OperatorMeaningExampleResult
==Equal to1 == 1True
!=Not equal to1 != 2True
<Less than1 < 2True
>Greater than1 > 2False
<=Less than or equal to1 <= 1True
>=Greater than or equal to2 >= 3False
The course shows that comparison works on strings as well as numbers — and that Python is case-sensitive:
# resultado = "Texto" == "texto"   # False — case mismatch
# resultado = "Texto" == "Texto"   # True  — exact match

Section 3 — Logical Operators

Logical operators combine boolean expressions. Python provides two: and (both sides must be True) and or (at least one side must be True).

The and Operator

and returns True only when both operands are True. If either side is False, the whole expression is False. Truth table for and:
LeftRightResult
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

The or Operator

or returns True when at least one operand is True. It is only False when both sides are False. Truth table for or:
LeftRightResult
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

Logical Operators in Code

The full program from the course demonstrates both operators, including a realistic login / password check using and:
semana1/operadoreslogicos.py
resultado = (1<11) and (21==2)
#Un and de como resultado true, ambos extremos deben ser true
print( resultado )

resultado = True and True
print("True and True")
print( resultado )

print(" True and False")
resultado = True and False
print( resultado )

print ("Login y password")
resultado = ("password" == "password") and ("correo"=="correo")
print( resultado )


#Compuerta Logica u Operador Logico
#Operador OR, es evaluar cada uno de sus extremos
#para verficar que uno sea verdadero

resultado = (1!=1) or (2!=2)
print ( "(1==1) or (2!=2)")
print(resultado)
Walk through each block:
1

Mixed and

(1<11) and (21==2) — the left side is True (1 is less than 11) but the right side is False (21 does not equal 2). Because and requires both to be true, the result is False.
2

True and True

Both sides are True, so the result is True.
3

True and False

One side is False, so the result is False.
4

Login and password check

("password" == "password") and ("correo" == "correo") — both strings match, so both sides are True, and the result is True. This is the fundamental pattern behind every login system.
5

or with two False values

(1!=1) or (2!=2)1!=1 is False and 2!=2 is False. Both sides are False, so even or returns False.

Build docs developers (and LLMs) love