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
+23-26Lines changed: 23 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -337,8 +337,8 @@ String
337
337
```
338
338
339
339
```python
340
-
<str>=chr(<int>) # Converts int to Unicode character.
341
-
<int>=ord(<str>) # Converts Unicode character to int.
340
+
<str>=chr(<int>) # Converts passed integer to Unicode character.
341
+
<int>=ord(<str>) # Converts passed Unicode character to integer.
342
342
```
343
343
***Use `'unicodedata.normalize("NFC", <str>)'` on strings like `'Motörhead'` before comparing them to other strings, because `'ö'` can be stored as one or two characters.**
344
344
***`'NFC'` converts such characters to a single character, while `'NFD'` converts them to two.**
@@ -972,17 +972,15 @@ class MyClass:
972
972
>>> obj.a, str(obj), repr(obj)
973
973
(1, '1', 'MyClass(1)')
974
974
```
975
-
***Return value of str() should be readable and of repr() unambiguous.**
976
-
***If only repr() is defined, it will also be used for str().**
977
-
***Methods decorated with `'@staticmethod'` do not receive 'self' nor 'cls' as their first argument.**
975
+
***Methods whose names start and end with two underscores are called special methods. They are executed when object is passed to a built-in function or used as an operand, for example, `'print(a)'` calls `'a.__str__()'` and `'a + b'` calls `'a.__add__(b)'`.**
976
+
***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().**
978
977
979
978
#### Expressions that call the str() method:
980
979
```python
981
980
print(<obj>)
982
981
f'{<obj>}'
983
982
logging.warning(<obj>)
984
983
csv.writer(<file>).writerow([<obj>])
985
-
raiseException(<obj>)
986
984
```
987
985
988
986
#### Expressions that call the repr() method:
@@ -991,11 +989,10 @@ print/str/repr([<obj>])
991
989
print/str/repr({<obj>: <obj>})
992
990
f'{<obj>!r}'
993
991
Z = make_dataclass('Z', ['a']); print/str/repr(Z(<obj>))
994
-
>>><obj>
995
992
```
996
993
997
994
### Subclass
998
-
***Inheritance is a mechanism that enables a class to extend another class (subclass to extend its parent), and by doing so inherit all its methods and attributes.**
995
+
***Inheritance is a mechanism that enables a class to extend some other class (that is, subclass to extend its parent), and by doing so inherit all its methods and attributes.**
999
996
***Subclass can then add its own methods and attributes or override inherited ones by reusing their names.**
1000
997
1001
998
```python
@@ -1694,7 +1691,7 @@ from pathlib import Path
1694
1691
```
1695
1692
1696
1693
```python
1697
-
<str>=str(<Path>) # Returns path as str. Also <Path>.as_uri().
1694
+
<str>=str(<Path>) # Returns path as string. Also <Path>.as_uri().
1698
1695
<file>=open(<Path>) # Also <Path>.read/write_text/bytes(<args>).
1699
1696
```
1700
1697
@@ -2765,7 +2762,7 @@ from PIL import Image
2765
2762
<Image>= Image.new('<mode>', (width, height)) # Creates new image. Also `color=<int/tuple>`.
2766
2763
<Image>= Image.open(<path>) # Identifies format based on file's contents.
2767
2764
<Image>=<Image>.convert('<mode>') # Converts image to the new mode (see Modes).
2768
-
<Image>.save(<path>) #Selects format based on extension (PNG/JPG…).
2765
+
<Image>.save(<path>) #Accepts `quality=<int>` if extension is jpg.
2769
2766
<Image>.show() # Displays image in default preview app.
2770
2767
```
2771
2768
@@ -2788,8 +2785,8 @@ from PIL import Image
2788
2785
```
2789
2786
2790
2787
### Modes
2791
-
***`'L'` - Lightness (greyscale image). Each pixel is an int between 0 and 255.**
2792
-
***`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three ints.**
2788
+
***`'L'` - Lightness (greyscale image). Each pixel is an integer between 0 and 255.**
2789
+
***`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three integers.**
2793
2790
***`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.**
2794
2791
***`'HSV'` - Hue, saturation, value. Three ints representing color in HSV color space.**
0 commit comments