This page (revision-7) was last changed on 2025-07-30 13:21 by Murray Altheim

This page was created on 2025-07-30 05:22 by Murray Altheim

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
7 2025-07-30 13:21 2 KB Murray Altheim to previous
6 2025-07-30 13:19 2 KB Murray Altheim to previous | to last
5 2025-07-30 13:17 2 KB Murray Altheim to previous | to last
4 2025-07-30 13:13 2 KB Murray Altheim to previous | to last
3 2025-07-30 12:58 1 KB Murray Altheim to previous | to last
2 2025-07-30 06:43 1 KB Murray Altheim to previous | to last
1 2025-07-30 05:22 1 KB Murray Altheim to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 11 changed one line
A class has a constructor, a special method named {{{__init__}}}. All special methods in Python are surrounded by double underscores. (There are more of these but we'll get to them later.)
A class has a __constructor__, a special method named {{{__init__}}}. The constructor is called when you create a new object of the class. It can be said that the new object has a type of its class.
At line 13 added 32 lines
%%filename boo.py %%
%%python {{{
class Boo:
__init__(self):
print('boo!')
}}} %%
%%repl {{{
/pyboard> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.25.0 on 2025-04-15; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>>
>>> from boo import Boo
>>> b = Boo()
boo!
>>>
>>> print(b)
<Boo object at 20005f50>
>>>
>>> print(type(b))
<class 'Boo'>
>>>
}}}
%%info
__What did we do?__
After creating a class named Boo, we imported the class ("from boo import Boo") so the interpreter was aware of it, then we ''instantiated'' (created an instance of) an object of the Boo class and we assigned the object a name "b". Then we printed the object (the interpreter returned a default result "<Boo object at 20005f50>"), then we printed the type of the object ("print(type(b))".
%%
All special methods in Python are surrounded by double underscores. (There are more of these but we'll get to them later.)