python-basics

Python fundamentals for beginners: variables, data types, operators, control flow, and functions, the core syntax every Python program is built on.

Python: Recursion, Base Cases, Stack, Practical Examples

A function that calls itself sounds like a fast track to an infinite loop, yet Python recursion is one of the tidiest ways to walk a folder tree, sum a nested list, or compute a factorial. The secret is a stopping rule called the base case. This guide builds recursive functions step by step, watches the call stack grow and unwind, shows why a naive Fibonacci makes your laptop fan scream, and pins down when a plain loop wins instead. ... Read More

Python Function Arguments: Default, Keyword, *args, **kwargs

Some functions take exactly two values and refuse a third. Others, like print(), happily swallow whatever you hand them. The difference comes down to two small symbols, * and **, and learning Python args kwargs is how you write that second kind. This post covers default values, keyword arguments, *args, **kwargs, and the ordering rules that hold them all together. “Sparse is better than dense.” Tim Peters, The Zen of Python (PEP 20) Last Updated: July 2026 | Tested on: ... Read More

Python: Scope and the LEGB Rule (Local, Enclosing, Global)

Python scope decides where a variable name is visible and where it is invisible. This post unpacks the LEGB rule (Local, Enclosing, Global, Built-in), the one mental model that explains how Python finds the right variable, plus the two keywords (global and nonlocal) that let you reach across scope lines. Every example below was run on Python 3.14.6. “Namespaces are one honking great idea, let’s do more of those!” Tim Peters, The Zen of Python (PEP 20) Last Updated: July ... Read More