Original Translation
20
>>> 1.1 - 0.9 0.20000000000000007 >>> print(1.1 - 0.9) 0.2
21
One of the consequences of this is that it is error-prone to compare the result of some computation to a float with ``==``. Tiny inaccuracies may mean that ``==`` fails. Instead, you have to check that the difference between the two numbers is less than a certain threshold::
22
epsilon = 0.0000000000001 # Tiny allowed error expected_result = 0.4 if expected_result-epsilon <= computation() <= expected_result+epsilon: ...
23
Please see the chapter on :ref:`floating point arithmetic <tut-fp-issues>` in the Python tutorial for more information.
24
Why are Python strings immutable?
25
There are several advantages.
26
One is performance: knowing that a string is immutable means we can allocate space for it at creation time, and the storage requirements are fixed and unchanging. This is also one of the reasons for the distinction between tuples and lists.
27
Another advantage is that strings in Python are considered as "elemental" as numbers. No amount of activity will change the value 8 to anything else, and in Python, no amount of activity will change the string "eight" to anything else.
28
Why must 'self' be used explicitly in method definitions and calls?
29
The idea was borrowed from Modula-3. It turns out to be very useful, for a variety of reasons.