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.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.
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 withinput() and converting that input from a string to a number with int().
semana1/operaciones.py
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:| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | variablea + variableb | 45 |
- | Subtraction | variablea - variableb | 15 |
* | Multiplication | variablea * variableb | 450 |
/ | Division | variablea / variableb | 2.0 |
input():
semana1/operaciones.py (commented examples)
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.
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | Equal to | 1 == 1 | True |
!= | Not equal to | 1 != 2 | True |
< | Less than | 1 < 2 | True |
> | Greater than | 1 > 2 | False |
<= | Less than or equal to | 1 <= 1 | True |
>= | Greater than or equal to | 2 >= 3 | False |
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:
| Left | Right | Result |
|---|---|---|
True | True | True |
True | False | False |
False | True | False |
False | False | False |
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:
| Left | Right | Result |
|---|---|---|
True | True | True |
True | False | True |
False | True | True |
False | False | False |
Logical Operators in Code
The full program from the course demonstrates both operators, including a realistic login / password check usingand:
semana1/operadoreslogicos.py
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.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.