Apple Pencil
For Apple Pencil, you may double tap to switch between eraser and your last selected tool.
Samsung S-Pen (Air Actions)
To learn more, here's a video tutorial from Samsung on Air actions.
Xiaomi Pen
OnePlus/Oppo Pen
Vivo Pen
Note that this only works on Vivo pens later than Vivo Pencil 2 / iQOO Pencil.
Lenovo Pen
Note that this only works on certain Lenovo pens, e.g., Lenovo Precision Pen 3, Lenovo Tab Pen Plus
Huawei M-Pencil
You may double tap to switch between eraser and your last selected tool.
For this to work, Make sure to disable stylus shortcut in Settings > Accessibility features > Stylus > Double-tap, make sure that "Open shortcut menu" is de-selected.
EMR stylus
For EMR stylus with an eraser button at its end, you may use the eraser button to perform erase action.
Long press to switch to eraser
On some stylus pens (e.g., Samsung S-Pen, Lenovo Precision Pen 2), when the stylus is close to the screen, you may long press the primary button to switch to eraser.