The micro:bit has a register mapped into it's memory called the FICR (Factory Information Configuration Register) that stores information programmed in at manufacturing time. One of the items programmed in is a unique* serial number. 


You can use this to identify the micro:bit in your program. Here's how to show the serial number on the display


MakeCode

basic.showNumber(control.deviceSerialNumber())


MicroPython

from microbit import *
import machine

def get_serial_number(type=hex):
    NRF_FICR_BASE = 0x10000000
    DEVICEID_INDEX = 25 # deviceid[1]
    return type(machine.mem32[NRF_FICR_BASE + (DEVICEID_INDEX*4)]& 0xFFFFFFFF)

# Scroll the serial number on the LED display
display.scroll(get_serial_number())

Further Information


Also see How do I find the name of my micro:bit?


NRF51 SDK header file with register map

https://github.com/lancaster-university/nrf51-sdk/blob/85dd2e7af27edb11b056efcda34a76cf8757ef47/source/nordic_sdk/components/device/nrf51.h#L1076-L1106


* The serial is actually a 64-bit factory generated pseudo-random number etched into each processor. Only 32 bits are used here though (as that makes it consistent for all the micro:bit higher level languages to deal with), and still enables it to be unique for most practical applications. To put this into context, you'd need about 100,000 to 250,000 micro:bits in one place to expect a duplication.


Based on this idea https://gist.github.com/microbit-carlos/d3110c69ee30ee2c92feca1397105cb0



Keywords for search: name, rename, ID