While you will probably mostly use your guns in Borderlands 3, it's great to be able to fend off an enemy with a melee attack every once in a while. Melee attacks can also be used for breaking breakables that drop loot, so it's a great way for opening these without wasting ammo.
Using a Melee attack in Borderlands 3 is pretty easy; all you need to do is to press the R3 button on PS4, the RS button on Xbox One, or the V key on PC. As for the consoles, these buttons are pressed by pushing down the right control stick. And that's all there is to using a melee attack in Borderlands 3.