This is an additional exercise of the MicroPython Tutorial.
In Python, everything is an object.
A name in Python is a reference (or binding) to an object. Names are created when you assign a value to a variable, define a function, class, module, or use import.
A Python object is a piece of data stored in memory that has:
This is true for:
In Python, a name is simply an identifier that refers to an object in memory. Think of it as a label or tag that points to a value.
It may seem a bit strange, but in Python while strings have no attributes, they do have methods. Quite a few of them in fact, too many to list all of them here.
When you want to know what methods are available for a given type of object, you should consult the Python or MicroPython documentation. Because MicroPython is targeted for very small devices it doesn't support all the same features as the full Python version. In this case, the string method capitalize() is available in Python but not MicroPython, so the interpreter spits out an error message:
Note that executing these methods on the string do not alter its stored value, only return the result of the method being applied to the string. This is proved by the last print(x).