THE FOUNDATIONS / ONE CONCEPT AT A TIME
Python Foundation.
Same value. Different object.
Explore is vs ==. Edit Python, move references, and watch the diagram change.
A space. An empty string.
Compare ' ' and ''. Edit the text and see exactly where each substring matches.
When integers meet floats.
Explore int + float, compare division operators, and follow the type of each result.
Position gives order. Keywords give names.
Explore positional and keyword arguments. Edit a function call, trace each value, and see why some calls raise errors.
Interactive notebook · English · Opens in a new tab05 / PYTHON ESSENTIALS
Mapping & joining values.
map(function, iterable) lazily applies a function to each item. For example, list(map(str, [1, 2, 9])) produces ['1', '2', '9'].
digits = [1, 2, 9]
strings = list(map(str, digits)) # ["1", "2", "9"]
number = int("".join(map(str, digits))) # 129separator.join(strings) combines strings with the chosen separator. "".join(["1", "2", "9"]) gives "129", while "-".join(...) gives "1-2-9". The elements must be strings.
06 / STRING OPERATIONS
Splitting strings into pieces.
text.split(separator) divides one string into a list of strings. Without a separator it splits on whitespace. It does not split a digit string into individual characters by default.
"1,2,9".split(",") # ["1", "2", "9"]
"1 2 9".split() # ["1", "2", "9"]
"129".split() # ["129"]
list("129") # ["1", "2", "9"]
list(map(int, "129")) # [1, 2, 9]Join vs split: join combines strings, while split separates a string. Both operations return new objects.