Hey, a language I know a lot about. Yeah, the most common implementation of Python is CPython, but there is also PyPi (a stackless implementation of CPython), Jython (Java implementation), IronPython (.NET implementation), and pypy.js (implementation of PyPy using Javascript using asm.js). I am actually personally hoping the guys being pypy.js convert it to use WebAssembly instead of asm.js. If they solved the performance issues in pypy.js, you could actually build a full Website using Python and no Javascript. That is the whole idea behind WebAssembly is to be kind of like the JVM or .NET Runtime, but in a Web browser so you can make sites without Javascript.
Anyways, to the original question, yeah Python, as well as most "scripting" languages actually have everything as variables, including functions.
>>> def test():
... return 1
...
>>> test
<function test at 0x7f9f76e6ebf8>
>>> test()
1
>>> type(test)
<class 'function'>
>>>
Functions can be manipulated just like any other variable and allow them to do a lot of really interesting things actually. Most notable are decorators. Decorators let you do all kind of cool and weird stuff. For example, C# has an interesting idea of how getters/setters function on classes via something called "Properties"
class TimePeriod
{
private double seconds;
public double Hours
{
get { return seconds / 3600; }
set {
if (value < 0 || value > 24)
throw new ArgumentOutOfRangeException(
$"{nameof(value)} must be between 0 and 24.");
seconds = value * 3600;
}
}
}
Python has something similar via the "property" decorator.
>>> class A():
... _test = 10
... @property
... def test(self):
... return self._test
... @test.setter
... def test(self, value):
... self._test = value
...
>>> a = A()
>>> a.test
10
>>> a._test
10
>>> a.test = 20
>>> a.test
20
>>> a._test
20
>>>
Also, as you can see from the above example, Python does not actually have access modifiers like C++/Java/C# does. Everything is "technically" public, but generally anything that is prefixed with _ is considered "private" in terms of the implementation API. If you make a member start with _, you are basically saying, "In a future version of this application, I can remove this member and it will be considered a non-breaking change".