Variables and Types

Using Python as a Calculator

  • Numbers

Expression syntax is straightforward: the operators +-* and /

The integer numbers (e.g. 2, 4, 20) have type int, the ones with a fractional part (e.g. 5.0, 1.6) have type float.

2+2
50-5*6
(50-5*6)/4
  • Strings

They can be enclosed in single quotes (‘…’) or double quotes (“…”) with the same result. \ can be used to escape quotes:

'spam eggs' # single quotes
' "Yes," they said.'
'\"Yes,\" they said.'
' "Isn\'t," they said.'