Operators

Operators are special symbols that represent computations, and the [[values]] that operators operate on are called operands.

The operators +-*/, and ** perform addition, subtraction, multiplication, division, and exponentiation, as in the following examples:

20+32
hour-1
hour*60+minute
minute/60
5**2
(5+9)*(15-7)
[[String]] [[Operators]]

You can add two strings together and this is called [[Concatenation|concatenation]].

>>> first = '100'
>>> second = '150'
>>> print(first + second)
100150

When you multiply a [[string]] with an [[integer]], you can create a new [[string]] with repetition.

>>> first = 'Test '
>>> second = 3
>>> print(first * second)
Test Test Test
[[Python]] Specific

In [[Python]] 3.0, dividing two [[Integer|integers]] result in a [[Float|float]]. However, in [[Python]] 2.0 this results in an [[Integer|integer]]. However, if you do:

>>> minute = 59
>>> minute//60
0

you get 0 because it is floored division. This is in [[Python]] 3.0.

Tags: #ComputerScience Sources: https://www.py4e.com/html3/02-variables Links: