Operands and Expressions
Once you can store data in variables, the next step is learning how to work with that data. This is where operands and expressions come in. An operand is a value used in a computation, and an expression is a combination of operands and operators that produces a result.
Common Types of Operators
- Arithmetic operators:
+,-,*,/,%,** - Comparison operators:
==,!=,>,<,>=,<= - Logical operators:
and,or,not - Assignment operators:
=,+=,-=,*=
price = 250
quantity = 4
total = price * quantity # expression using arithmetic operator
is_bulk_order = quantity >= 3 # expression using comparison operator
Expressions are the core of decision-making in code. Almost every condition, calculation, and comparison in a data science script is built from simple expressions like these.
Where This Leads
With operators and expressions in hand, you're ready to make your programs respond differently based on conditions, which is exactly what conditional statements are for.