FREE INTERACTIVE ONLINE COURSE

Python 3

FOR BEGINNERS


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)


ALL REVIEWS
LESSON 2
PAGE 1 / 4
Mathematical Operators
Home >>> Free Online Lessons, Python 3

About Expressions

To perform calculations, programs use expressions. You've already used them in the first lesson!

Definition 1. An expression is a sequence composed of one or more operands, linked together by operators, according to specific syntactic rules of the programming language.

For example, in the expression 3 + 4*2
3, 4, and 2 are operands, and + and * are operators.

An incorrectly written expression will lead to a syntax error:



During the execution of the Python program, expressions are evaluated (i.e., a result is calculated).

Arithmetic operators can be unary or binary.

Unary Operators

Unary operators (+ and -) act on a single operand that is always located to the right of the operator. The "+" operator returns the operand's value, while the "-" operator returns the operand's value with the sign changed.

Examples: -23, +11

Binary Operators

Binary operators (+, -, *, /, //, and %) act on two operands. One operand is always on the left of the operator, and the other is on the right.

Examples: 10+5, 5-2, 7*5, etc.

We will further analyze some specific characteristics of three operators.

These concepts are very important!
If you have finished reading, proceed to the next page.
 home   list  CONTENTS   perm_identity   arrow_upward