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
Copy file name to clipboardExpand all lines: README.md
+40-41Lines changed: 40 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -974,20 +974,20 @@ class MyClass:
974
974
***Methods decorated with `'@staticmethod'` receive neither 'self' nor 'cls' argument.**
975
975
***Return value of str() special method should be readable and of repr() unambiguous. If only repr() is defined, it will also be used for str().**
976
976
977
-
#### Expressions that call object's str() special method:
977
+
#### Expressions that call str() special method:
978
978
```python
979
979
f'{obj}'
980
980
print(obj)
981
981
logging.warning(obj)
982
982
<csv_writer>.writerow([obj])
983
983
```
984
984
985
-
#### Expressions that call object's repr() special method:
***Objects can be made [sortable](#sortable) with `'order=True'` and immutable with `'frozen=True'`.**
1043
-
***For object to be [hashable](#hashable), all attributes must be hashable and arg. 'frozen' must be True.**
1044
-
***Function field() is needed because `'<attr_name>: list = []'` would make a list that isshared among all instances. Its 'default_factory' argument accepts any [callable](#callable) object.**
1043
+
***For object to be [hashable](#hashable), all attributes must be hashable and `'frozen'` must be `'True'`.**
1044
+
***Function field() is needed because `'<attr_name>: list = []'` would make a list that is shared among all instances. Its 'default_factory' argument accepts any [callable](#callable) object.**
1045
1045
***For attributes of arbitrary type use `'typing.Any'`.**
1046
1046
1047
1047
#### Inline:
@@ -1093,7 +1093,7 @@ Duck Types
1093
1093
### Comparable
1094
1094
***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 memory address that is guaranteed to be unique).**
1095
1095
***Only the left side object has eq() method called, unless it returns NotImplemented, in which case the right object is consulted. Result is False if both return NotImplemented.**
1096
-
***Ne() automatically works on any object that has eq() defined.**
1096
+
***Method ne() (called by `'!='`) automatically works on any object that has eq() defined.**
1097
1097
1098
1098
```python
1099
1099
classMyComparable:
@@ -1107,7 +1107,7 @@ class MyComparable:
1107
1107
1108
1108
### Hashable
1109
1109
***Hashable object needs both hash() and eq() methods and its hash value must not change.**
1110
-
***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().**
1110
+
***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 the eq() method.**
1111
1111
1112
1112
```python
1113
1113
classMyHashable:
@@ -1173,7 +1173,7 @@ class Counter:
1173
1173
***Sequence iterators returned by the [iter()](#iterator) function, such as list\_iterator, etc.**
1174
1174
***Objects returned by the [itertools](#itertools) module, such as count, repeat and cycle.**
1175
1175
***Generators returned by the [generator functions](#generator) and [generator expressions](#comprehensions).**
1176
-
***File objects returned by the [open()](#open) function, etc.**
1176
+
***File objects returned by the [open()](#open) function, [SQLite](#sqlite) cursor objects, etc.**
1177
1177
1178
1178
### Callable
1179
1179
***All functions and classes have a call() method that is executed when they are called.**
@@ -1535,18 +1535,17 @@ arguments = sys.argv[1:]
1535
1535
### Argument Parser
1536
1536
```python
1537
1537
from argparse import ArgumentParser
1538
-
p = ArgumentParser(description=<str>) # Returns a parser object.
1539
-
p.add_argument('-<short_name>', '--<name>', action='store_true') # Flag (defaults to False).
1540
-
p.add_argument('-<short_name>', '--<name>', type=<type>) # Option (defaults to None).
1541
-
p.add_argument('<name>', type=<type>, nargs=1) # Mandatory first argument.
0 commit comments