Читать книгу Learn Python quick - Jens Braun - Страница 12

Basic Operators

Оглавление

Besides assigning a variable an initial value, we can also perform the usual mathematical operations on variables. Basic operators in Python include +, -, *, /, //, % and ** which represent addition, subtraction, multiplication, division, floor division, modulus and exponent respectively.

Example:

Suppose x = 5, y = 2

Addition:

x + y = 7

Subtraction:

x - y = 3

Multiplication:

x*y = 10

Division:

x/y = 2.5

Floor Division:

x//y = 2 (rounds down the answer to the nearest whole number)

Modulus:

x%y = 1 (gives the remainder when 5 is divided by 2)

Exponent:

x**y = 25 (5 to the power of 2)

Learn Python quick

Подняться наверх