The method move_and_slide internally takes your velocity, moves the character, and if it collides with something, it the function tries to slide the character against the collision surface and calculates a new velocity.
The function can do this several times in a loop, then, it returns the last calculated velocity, which we can choose to store and use or not. That velocity will not always be of length zero, but if you hit a wall face-on, it should go down to zero.