LAWSON DONG / FIELD NOTES
Leave me a message
Coding and AI Engineering/Python Foundation

THE FOUNDATIONS / ONE CONCEPT AT A TIME

Python Foundation.

01 / RUN IN GOOGLE COLAB

Same value. Different object.

Explore is vs ==. Edit Python, move references, and watch the diagram change.

Interactive notebook · English · Opens in a new tab
View or download on GitHub ↗
02 / RUN IN GOOGLE COLAB

A space. An empty string.

Compare ' ' and ''. Edit the text and see exactly where each substring matches.

Interactive notebook · English · Opens in a new tab
View or download on GitHub ↗
03 / RUN IN GOOGLE COLAB

When integers meet floats.

Explore int + float, compare division operators, and follow the type of each result.

Interactive notebook · English · Opens in a new tab
View or download on GitHub ↗
04 / RUN IN GOOGLE COLAB

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 tab
View or download on GitHub ↗

05 / 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)))  # 129

separator.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.

Practice: LeetCode 66 — Plus One (two approaches) ↗

AI STOPPED
Astra

Ready for our next conversation.

Nemi

Ready for our next conversation.

0/50 · Local conversation