You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***Times and datetimes that have defined timezone are called aware and ones that don't, naive. If object is naive, it is presumed to be in the system's timezone!**
607
606
***`'fold=1'` means the second pass in case of time jumping back for one hour.**
608
607
***Timedelta normalizes arguments to ±days, seconds (< 86 400) and microseconds (< 1M). Its str() method returns `'[±D, ]H:MM:SS[.…]'` and total_seconds() a float of all seconds.**
609
-
***Use `'<D/DT>.weekday()'` to get the day of the week as an int, with Monday being 0.**
608
+
***Use `'<D/DT>.weekday()'` to get the day of the week as an integer, with Monday being 0.**
610
609
611
610
### Now
612
611
```python
@@ -1076,7 +1075,7 @@ class Person:
1076
1075
```
1077
1076
1078
1077
### Slots
1079
-
**Mechanism that restricts objects to attributes listed in 'slots', reduces their memory footprint.**
1078
+
**Mechanism that restricts objects to attributes listed in 'slots'.**
1080
1079
1081
1080
```python
1082
1081
classMyClassWithSlots:
@@ -1097,8 +1096,7 @@ Duck Types
1097
1096
**A duck type is an implicit type that prescribes a set of special methods. Any object that has those methods defined is considered a member of that duck type.**
1098
1097
1099
1098
### Comparable
1100
-
***If eq() method is not overridden, it returns `'id(self) == id(other)'`, which is the same as `'self is other'`.**
1101
-
***That means all user-defined objects compare not equal by default.**
1099
+
***If eq() method is not overridden, it returns `'id(self) == id(other)'`, which is the same as `'self is other'`. That means all user-defined objects compare not equal by default, because id() returns object's unique identification number (its memory address).**
1102
1100
***Only the left side object has eq() method called, unless it returns NotImplemented, in which case the right object is consulted. False is returned if both return NotImplemented.**
1103
1101
***Ne() automatically works on any object that has eq() defined.**
1104
1102
@@ -1113,9 +1111,8 @@ class MyComparable:
1113
1111
```
1114
1112
1115
1113
### Hashable
1116
-
***Hashable object needs both hash() and eq() methods and its hash value should never change.**
1117
-
***Hashable objects that compare equal must have the same hash value, meaning default hash() that returns `'id(self)'` will not do.**
1118
-
***That is why Python automatically makes classes unhashable if you only implement eq().**
1114
+
***Hashable object needs both hash() and eq() methods and its hash value must not change.**
1115
+
***Hashable objects that compare equal must have the same hash value, meaning default hash() that returns `'id(self)'` will not do. That is why Python automatically makes classes unhashable if you only implement eq().**
1119
1116
1120
1117
```python
1121
1118
classMyHashable:
@@ -1133,7 +1130,7 @@ class MyHashable:
1133
1130
```
1134
1131
1135
1132
### Sortable
1136
-
***With 'total_ordering' decorator, you only need to provide eq() and one of lt(), gt(), le() or ge() special methods and the rest will be automatically generated.**
1133
+
***With 'total_ordering' decorator, you only need to provide eq() and one of lt(), gt(), le() or ge() special methods (used by <, >, <=, >=) and the rest will be automatically generated.**
1137
1134
***Functions sorted() and min() only require lt() method, while max() only requires gt(). However, it is best to define them all so that confusion doesn't arise in other contexts.**
1138
1135
***When two lists, strings or dataclasses are compared, their values get compared in order until a pair of unequal values is found. The comparison of this two values is then returned. The shorter sequence is considered smaller in case of all values being equal.**
1139
1136
***To sort collection of strings in proper alphabetical order pass `'key=locale.strxfrm'` to sorted() after running `'locale.setlocale(locale.LC_COLLATE, "en_US.UTF-8")'`.**
@@ -1205,7 +1202,7 @@ class Counter:
1205
1202
### Context Manager
1206
1203
***With statements only work on objects that have enter() and exit() special methods.**
1207
1204
***Enter() should lock the resources and optionally return an object.**
1208
-
***Exit() should release the resources.**
1205
+
***Exit() should release the resources (for example close a file).**
1209
1206
***Any exception that happens inside the with block is passed to the exit() method.**
1210
1207
***The exit() method can suppress the exception by returning a true value.**
1211
1208
```python
@@ -1530,7 +1527,7 @@ Input
1530
1527
```
1531
1528
***Reads a line from the user input or pipe if present (trailing newline gets stripped).**
1532
1529
***If argument is passed, it gets printed to the standard output before input is read.**
1533
-
***EOFError is raised if user hits EOF (ctrl-d/ctrl-z⏎) or if input stream is exhausted.**
1530
+
***EOFError is raised if user hits EOF (ctrl-d/ctrl-z⏎) or if stream is already exhausted.**
1534
1531
1535
1532
1536
1533
Command Line Arguments
@@ -1955,22 +1952,22 @@ Bytes
1955
1952
1956
1953
```python
1957
1954
<bytes>=b'<str>'# Only accepts ASCII characters and \x00-\xff.
1958
-
<int>=<bytes>[index] # Returns an int in range from 0 to 255.
1955
+
<int>=<bytes>[index] # Returns an integer in range from 0 to 255.
1959
1956
<bytes>=<bytes>[<slice>] # Returns bytes even if it has only one element.
1960
-
<bytes>=<bytes>.join(<coll_of_bytes>) # Joins elements using bytes as a separator.
1957
+
<bytes>=<bytes>.join(<coll_of_bytes>) # Joins elements by using bytes as a separator.
1961
1958
```
1962
1959
1963
1960
### Encode
1964
1961
```python
1965
-
<bytes>=bytes(<coll_of_ints>) #Ints must be in range from 0 to 255.
1962
+
<bytes>=bytes(<coll_of_ints>) #Integers must be in range from 0 to 255.
1966
1963
<bytes>=bytes(<str>, 'utf-8') # Encodes the string. Also <str>.encode().
1967
1964
<bytes>=bytes.fromhex('<hex>') # Hex pairs can be separated by whitespaces.
0 commit comments