🈁 Strings and bytes
👇 Strings
.encode("utf-8")
🔄 .decode("utf-8")
☝️ Bytes
💬 Escape sequences, raw strings
see all here
str
� unicode
😮 Unicode 13.0 – 143 859 characters
…what are those for?
🤔 How much bits (bytes) are used to represent symbols?
hint: encoding
PEP-393
Universal Character Set
N bytes for each symbol
- UCS-1 ⬅️ ASCII
- UCS-2 ⬅️ max code < 2
- UCS-4 ⬅️ everything else
💨 Quick basic methods overview
1️⃣ Registry modificators
2️⃣ Nice output
3️⃣ Removing symbols
4️⃣ Splitting strings
5️⃣ Joining strings
6️⃣ Finding things
7️⃣ Replacing things
8️⃣ Useful predicates
FYI: you don’t need to remember formatting symbols (use docs!)
Formatting: please, don’t
- % is binary, requires list/tuple
- every element is used only once
- problems with long numbers
import string
Strings and bytes wrap-up
- strings are sequences of codepoints (Unicode sequences), symbol is a string too
- cool methods for bytes and strings
- Universal Character Set: N bytes for symbol (1, 2, 4)
- don’t use
%
, use f""
and"".forma
- do not confuse bytes and strings
📂 Files and IO
🚀 Files opening
modes: “r”, “w”, “x”, “a”, ”+”, “b”, “t”.
Reading and writing
Other functions
🎶 Three default text files
🆕 from pathlib import Path
🔥 Files and IO wrap-up
- files can be texts or bytes
- methods of reading writing are typical
- Python has stdin, stdout and stderr – text files
- methods are typical, pathlib is useful
Collections
set
frozenset
Supports all set operations except adding/removing elements.
tuple
namedtuple
list
tuple and list
- reversed()
- concatenation: x + y (always a new object)
but inplace concatenation in list!
by the way…
dict
🏁 Any questions?