This is how we get the device name using MakeCode for micro:bit
But i can't find a way to do it in micropython.
And the Makecode python implementation throws an error in normal micropython:
from microbit import *
while True:
basic.show_string(control.device_name())
micropython for the micro:bit is different from the code used in the MakeCode editor.
They are both based on Hardware Abstraction Layer defined at the following location: https://lancaster-university.github.io/microbit-docs/concepts/
The documentation for micropython is available at: https://microbit-micropython.readthedocs.io/en/v1.0.1/microbit_micropython_api.html
There is not a unique name in the same way that there is in blocks.