Basic types
Let's go over the basic data types that you will encounter in Python.
Numbers
A number may be an integer, a real number, or a complex number. The usual operations are:
- addition and subtraction,
+
and-
- multiplication and division,
*
and/
- power,
**
Here is an example:
2 ** (2 + 2) # 16 1j ** 2 # -1 1. + 3.0j
Note
The symbol for complex numbers
j
is a symbol to denote the imaginary part of a complex number.
It is a syntactic element and should not be confused with multiplication by a variable. More on complex numbers can be found in section Numeric Types of Chapter 2, Variables and Basic Types.
Strings
Strings are sequences of characters, enclosed by simple or double quotes:
'valid string' "string with double quotes" "you shouldn't forget comments" ...
Get Scientific Computing with Python 3 now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.