July 2023
Beginner to intermediate
448 pages
10h 57m
English
Now that we’ve taken a look at strings and lists (plus tuples and sets), we’ll continue with a tour of some other important Python features and objects: math, dates, regular expressions, and dictionaries.
Like most programming languages, Python supports a large number of mathematical operations:
$ source venv/bin/activate
(venv) $ python3
>>> 1 + 1
2
>>> 2 - 3
-1
>>> 2 * 3
6
>>> 10/5
2.0
Note that division gives you the answer that you’d expect:
>>> 10/4
2.5
>>> 2/3
0.6666666666666666
We see here that Python uses floating-point division by default. This stands in contrast to some other languages, such as C and Ruby, in which / is integer division that returns the number of times the denominator goes into ...
Read now
Unlock full access