You cannot use the Raspberry Pi 3 as a USB gadget. At the time of writing this is only possible on the Raspberry Pi 0, 0W, A, A+, and 4. The Pi B, B+, 2, 3, 3A+, and 3B+ lack the required pin for OTG.

If you have a Pi Zero, [this gist](https://gist.github.com/gbaman/50b6cca61dd1c3f88f41) has some examples that work with minimal configuration like `g_serial`, `g_ether`, or `g_multi`. For example, a minimal way to enable the serial gadget is to add `dtoverlay=dwc2` to /boot/config.txt and `g_serial` to /etc/modules

lukas2005's original answer linked to [iSticktoit.net's examples](https://www.isticktoit.net/?p=1383) of using the more modern ConfigFS approach. The keyboard HID example is a good one to start with. And when you have only one functional micro-USB port, it becomes particularly valuable to configure multiple gadgets at a time, something that is not as readily available with the old `g_*` kernel modules.