Skip to content

Commit 0611fcb

Browse files
committed
🎨 Rearrange numbers section
1 parent c567e13 commit 0611fcb

File tree

11 files changed

+137
-127
lines changed

11 files changed

+137
-127
lines changed

docs/appendix/checks.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Checks
5050
``very_very_long_var_name``
5151
✅ ok, but very long and therefore only recommended if you want to differentiate between many very similar variables
5252

53-
:doc:`/types/numbers`
54-
---------------------
53+
:doc:`/types/numbers/index`
54+
---------------------------
5555

5656
* Create some number variables (integers, floating point numbers and complex
5757
numbers). Experiment a little with what happens when you perform operations
@@ -81,6 +81,9 @@ Checks
8181
8282
.. blacken-docs:on
8383
84+
:doc:`/types/numbers/complex`
85+
-----------------------------
86+
8487
* Load the :mod:`math` module and try out some of the functions. Then load the
8588
:mod:`cmath` module and do the same.
8689

@@ -101,6 +104,9 @@ Checks
101104
>>> sqrt(3)
102105
1.7320508075688772
103106
107+
:doc:`/types/numbers/bool`
108+
--------------------------
109+
104110
* Decide whether the following statements are true or false:
105111

106112
* ``1`` → True

docs/functions/params.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Mutable objects as arguments
224224

225225
Arguments are passed by object reference. The parameter becomes a new reference
226226
to the object. With immutable objects such as :doc:`/types/tuples`,
227-
:doc:`/types/strings/index` and :doc:`/types/numbers`, what is done with a
227+
:doc:`/types/strings/index` and :doc:`/types/numbers/index`, what is done with a
228228
parameter has no effect outside the function. However, if you pass a mutable
229229
object, such as a :doc:`/types/lists`, a :doc:`/types/dicts` or a class
230230
instance, any change to the object changes what the argument refers to outside

docs/libs/batteries.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
In Python, a library can consist of several components, including built-in data
55
types and constants that can be used without an import statement, such as
6-
:doc:`/types/numbers` and :doc:`/types/lists`, as well as some built-in
6+
:doc:`/types/numbers/index` and :doc:`/types/lists`, as well as some built-in
77
:doc:`/functions/index` and :doc:`/control-flows/exceptions`. The largest part
88
of the library is an extensive collection of :doc:`/modules/index`. If you have
99
Python installed, there are also several libraries available for you to use.

docs/save-data/pickle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ this state in a file called ``data.pickle`` as follows:
4040
instances of user-defined classes. :py:func:`pickle.dump` saves everything.
4141

4242
The pickle module can store almost anything in this way. It can handle
43-
:doc:`/types/numbers`, :doc:`/types/lists`, :doc:`/types/tuples`,
43+
:doc:`/types/numbers/index`, :doc:`/types/lists`, :doc:`/types/tuples`,
4444
:doc:`/types/dicts`, :doc:`/types/strings/index` and pretty much anything
4545
made up of these object types, including all class instances. It also
4646
handles shared objects, cyclic references and other complex storage

docs/types/dicts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ available.
2424
>>> x.get(5, "nicht vorhanden")
2525
'nicht vorhanden'
2626
27-
Keys must be of immutable type, including :doc:`numbers`, :doc:`strings/index`
28-
and :doc:`tuples`.
27+
Keys must be of immutable type, including :doc:`numbers/index`,
28+
:doc:`strings/index` and :doc:`tuples`.
2929

3030
.. warning::
3131
Even if you can use different key types in a dictionary, you should avoid

docs/types/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ values to more complex structures like lists, dictionaries and files.
4444
:titlesonly:
4545
:hidden:
4646

47-
numbers
47+
numbers/index
4848
lists
4949
tuples
5050
sets

docs/types/lists.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ A list in Python is similar to an array in Java or C: an ordered collection of
55
objects. However, unlike lists in many other languages, Python lists can contain
66
different types of elements; a list element can be any Python object, including
77
:doc:`strings/index`, :doc:`tuples`, :doc:`lists`, :doc:`dicts`,
8-
:doc:`../functions/index`, :doc:`files` and any kind of :doc:`numbers`. You
9-
create a list by enclosing no elements or elements separated by commas in square
10-
brackets, like this:
8+
:doc:`../functions/index`, :doc:`files` and any kind of :doc:`numbers/index`.
9+
You create a list by enclosing no elements or elements separated by commas in
10+
square brackets, like this:
1111

1212
.. code-block:: python
1313
:linenos:
@@ -381,8 +381,8 @@ Minimum or maximum of a list
381381

382382
You can use :func:`max` and :func:`min` to find the largest and smallest
383383
element of a list. You will probably use :func:`max` and :func:`min` mainly for
384-
:doc:`numeric </types/numbers>` lists, but you can also use them for lists with
385-
arbitrary elements; however, if the comparison of these types does not make
384+
:doc:`numeric </types/numbers/index>` lists, but you can also use them for lists
385+
with arbitrary elements; however, if the comparison of these types does not make
386386
sense, this will result in an error:
387387

388388
.. code-block:: pycon

docs/types/none.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ None
22
====
33

44
In addition to the standard types such as :doc:`strings/index` and
5-
:doc:`numbers`, Python has a special data type that defines a single special
6-
data object called ``None``. As the name suggests, ``None`` is used to represent
7-
an empty value. It appears in various forms in Python.
5+
:doc:`numbers/index`, Python has a special data type that defines a single
6+
special data object called ``None``. As the name suggests, ``None`` is used to
7+
represent an empty value. It appears in various forms in Python.
88

99
``None`` is often useful in everyday Python programming as a placeholder to
1010
indicate a data structure where meaningful data can eventually be found, even if

docs/types/numbers/bool.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Boolean values
2+
==============
3+
4+
Boolean values are used in the following examples:
5+
6+
.. code-block:: pycon
7+
8+
>>> x = False
9+
>>> x
10+
False
11+
>>> not x
12+
True
13+
14+
.. code-block:: pycon
15+
16+
>>> y = True * 2
17+
>>> y
18+
2
19+
20+
Apart from their representation as ``True`` and ``False``, Boolean values
21+
behave like the numbers ``1`` (``True``) and ``0`` (``False``).
22+
23+
Checks
24+
------
25+
26+
* Decide whether the following statements are true or false:
27+
28+
* ``1``
29+
* ``0``
30+
* ``-1``
31+
* ``[0]``
32+
* ``1 and 0``
33+
* ``1 > 0 or []``

docs/types/numbers/complex.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Complex numbers
2+
===============
3+
4+
Complex numbers consist of a real part and an `imaginary part
5+
<https://en.wikipedia.org/wiki/Imaginary_number>`_, which is given the suffix
6+
``j`` in Python.
7+
8+
.. code-block:: pycon
9+
10+
>>> 7 + 2j
11+
(7+2j)
12+
13+
.. note::
14+
15+
Python expresses the resulting complex number in parentheses to indicate
16+
that the output represents the value of a single object:
17+
18+
.. code-block:: pycon
19+
20+
>>> (5 + 3j) ** (3 + 5j)
21+
(-7.04464115622119-11.276062812695923j)
22+
23+
.. code-block:: pycon
24+
25+
>>> x = (5 + 3j) * (6 + 8j)
26+
>>> x
27+
(6+58j)
28+
>>> x.real
29+
6.0
30+
>>> x.imag
31+
58.0
32+
33+
Complex numbers consist of a real part and an imaginary part with the suffix
34+
``j``. In the preceding code, the variable ``x`` is assigned to a complex
35+
number. You can get its „real“ part with the attribute notation ``x.real`` and
36+
the „imaginary“ part with ``x.imag``.
37+
38+
Advanced functions
39+
------------------
40+
41+
The functions in the :doc:`math <python3:library/math>` module are not
42+
applicable to complex numbers; one of the reasons for this is probably that the
43+
square root of ``-1`` is supposed to produce an error. Therefore, similar
44+
functions for complex numbers have been provided in the :doc:`cmath
45+
<python3:library/cmath>` module:
46+
47+
:func:`python3:cmath.acos`, :func:`python3:cmath.acosh`, :func:`python3:cmath.asin`, :func:`python3:cmath.asinh`, :func:`python3:cmath.atan`, :func:`python3:cmath.atanh`, :func:`python3:cmath.cos`, :func:`python3:cmath.cosh`, :func:`python3:cmath.e`, :func:`python3:cmath.exp`, :func:`python3:cmath.log`, :func:`python3:cmath.log10`, :func:`python3:cmath.pi`, :func:`python3:cmath.sin`, :func:`python3:cmath.sinh`, :func:`python3:cmath.sqrt`, :func:`python3:cmath.tan`, :func:`python3:cmath.tanh`.
48+
49+
To make it clear in the code that these functions are special functions for
50+
complex numbers, and to avoid name conflicts with the more normal equivalents,
51+
it is recommended to simply import the module to explicitly refer to the
52+
``cmath`` package when using the function, for example:
53+
54+
.. code-block:: pycon
55+
56+
>>> import cmath
57+
>>> cmath.sqrt(-2)
58+
1.4142135623730951j
59+
60+
.. warning::
61+
62+
Now it becomes clearer why we do not recommend importing all functions of a
63+
module with :samp:`from {MODULE} import \*`. If you would import the module
64+
``math`` first and then the module ``cmath``, the functions in ``cmath``
65+
would have priority over those of ``math``. Also, when understanding the
66+
code, it is much more tedious to find out the source of the functions used.
67+
68+
Checks
69+
------
70+
71+
* Load the :mod:`math` module and try out some of the functions. Then load the
72+
:mod:`cmath` module and do the same.
73+
74+
* How can you restore the functions of the :mod:`math` module?

0 commit comments

Comments
 (0)