The accelerometer’s z sensing axis aligns with gravity when the micro:bit is held level with its LED display facing down. In that position, accelerometer.get_z() returns a measurement in the -1024 neighborhood.
Held vertically, it returns zero since the z-axis is perpendicular to gravit y— it doesn’t line up at all. If held vertically, rotation angle won’t matter to the z-axis, it still returns zero. Held with the LED display facing up, the z-axis is aligned with gravity again but pointing the opposite direction. Because of that, the accelerometer.get_z() function returns a value near -1024.
As for how the script test-z-axis-tilt works, it is basically the z-axis version of test_tilt_intro. The main difference is that:
x = accelerometer.get_x() y = accelerometer.get_y() print("x =", x, ", y =", y)
…has been replaced with
z = accelerometer.get_z() print("z =", z)