Skip to content

Python

Python syntax and standard libraries through testing, automation, data processing, and service implementation.

Articles

22 total

Python Requests: Check Timeouts, HTTP Status, and JSON Separately

Use a connect/read timeout with requests.get, then distinguish HTTP errors from invalid JSON and choose safe retry behavior.

Python3 min

Readable Python List Comprehensions: Filter, Transform, or Use a Loop

Keep simple filtering and transformation clear, and switch to a for loop when type checks, branches, or side effects obscure the result.

Python3 min

Python *args vs **kwargs: Collecting and unpacking function arguments

See how extra positional arguments become a tuple, keyword arguments become a dictionary, and stars at a call site unpack values.

Python2 min

Python dict.get() vs. Square Brackets: KeyError, None, and Defaults

Compare missing-key lookups, default values, and a key explicitly storing None using the same profile dictionary.

Python2 min

Python append() vs. extend(): Why Did a Nested List Appear?

Use the same event list to compare adding one list with adding its items, including join errors, None return values, and string inputs.

Python2 min

Why Python set Changes Deduplicated List Order: Preserve the First Occurrence

Compare list(set(items)), dict.fromkeys(), and sorted(set()) when removing duplicates with or without preserving input order.

Python2 min

Why Python list.sort() Returns None: In-Place Sorting vs. sorted()

See why assigning the result of list.sort() gives you None, and compare it with sorted(), which returns a new list without changing the original.

Python2 min

Python Local vs. Global Scope: Why UnboundLocalError Occurs

Understand why assignment inside a function creates a local variable and pass state through return values instead of relying on global.

Python3 min

Why a Python Function Returns None: Finding a Missing return

Learn why a function without an explicit return yields None and how to find branches that drop a result.

Python2 min

Python Truthy and Falsy Values: Distinguish None, Empty Strings, and Zero

Understand which values are false in an if statement and when input validation must distinguish None, empty strings, and 0.

Python3 min