O'Reilly logo

The Python Quick Syntax Reference by Gregory Walters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 3

image

Operators

Python supports several operators. Here, we review some of the key ones.

Arithmetic Operators

We use the arithmetic operators to do simple math on two variables or literals. Be sure to only try to use arithmetic operators on like types. For example, if you try to add a string value to a integer (3 + “ is a number”) you will get an error.

+ Addition

Adds the left value to the right:

>>> lvariable = 5>>> sum = lvariable + 3>>> sum8

− Subtraction

Subtracts the right value from left:

>>> lvariable = 5>>> difference = lvariable - 3>>> difference2

* Multiplication

Multiplies left value by right:

>>> lvariable = 5>>> product ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required