From 2a1762083b0f2f287383424e41df940638131e17 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Thu, 8 Jan 2026 19:45:25 +0000 Subject: [PATCH] update python notes --- zk/Tuples_in_Python.md | 10 +++++----- zk/Type_hinting.md | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/zk/Tuples_in_Python.md b/zk/Tuples_in_Python.md index b83e8ab..ee33029 100644 --- a/zk/Tuples_in_Python.md +++ b/zk/Tuples_in_Python.md @@ -2,10 +2,6 @@ tags: [python, data-structures] --- -# Tuples in Python - -TODO: Exapand tuple notes - give more use cases - Tuples are one of the main data-structures or containers in Python. Tuples are useful in cases where you want to group related data and ensure that it will not change. @@ -31,9 +27,13 @@ tup1 = (1, 3, 5, 7) print(tup1[2]) # 5 -""" ``` +> Really you should know in advance how long your tuple is going to be but if +> you just do `tup = ('shoe')` this will be processed by Python as a single +> string. Instead if you want to indicate that the tuple may be expanded later +> use `tup = ('shoe',)`. The comma converts it from a string to a tuple. + ## Slicing ```python diff --git a/zk/Type_hinting.md b/zk/Type_hinting.md index e615058..57dd061 100644 --- a/zk/Type_hinting.md +++ b/zk/Type_hinting.md @@ -4,8 +4,6 @@ tags: - data-types --- -# Type hinting in Python - With type hinting we can add type information to variables, functions, and classes. This is not enforced by the Python interpreter but can be used by external tools like `mypy` to check the code. @@ -109,7 +107,7 @@ def find_index(numbers: list[int], target: int) -> Optional[int]: The function above returns an `int` or `None`. -Post 3.10, we don't need to use `Optional`, we can use a union to cover the +From 3.11, we don't need to use `Optional`, we can use a union to cover the `None` case. Refactoring the previous example: ```py