POST 1 of 5 MorningPythonConcept
A function is a value in Python
Coming from Java or C++, the idea that 'a function is a value' takes some adjustment. In those languages, methods belong to classes, classes are first-class, methods aren't.
In Python, functions are first-class. That means a function — the def add(a, b): return a + b you wrote — is itself a value. It has a name, a type (function), and you can pass it around exactly like an int or a string.
Let me show you. Define add, sub, mul. Now do this:
ops = [add, sub, mul]
for op in ops:
print(op(2, 3))
You just iterated over functions and called each one. The interpreter didn't blink, because to it, ops is just a list of three values that happen to be callable.
This is the foundational fact behind a stack of features that show up in every Python codebase you'll ever read.
Decorators (Day 10) work because @my_decorator is shorthand for 'pass this function to my_decorator and replace it with the result'. That requires functions to be values.
Callbacks work — the on_click handlers in your UI library, the key= argument in sorted(), the loss function you pass into PyTorch's training loop — all of them depend on this.
Higher-order functions like map, filter, reduce work for the same reason.
This isn't a 'cool feature'. It's the bedrock for everything that makes modern Python ergonomic. Embrace it. Stop putting everything in classes (a Java reflex). Start writing small composable functions — they pass around freely, they test in isolation, they compose without ceremony.
Functions are first-class. Internalise it once and a lot of Python suddenly clicks.#AI#MachineLearning#Python#100DaysOfCode#BuildInPublic#FunctionalProgramming#PythonOOP