The versatile weapon property says (PHB, p. 147):
Versatile. This weapon can be used with one or two hands. A damage value in parentheses appears with the property–the damage when the weapon is used with two hands to make a melee attack.
A weapon with the versatile property, such as a longsword or a quarterstaff, can be wielded with one or two hands. Does it consume any part of the action economy to switch between using one or two hands on your turn?
Intuitively I’d say no, I imagine it costs absolutely nothing, but I can imagine, at worst, there being arguments for it costing your “free object interaction” (PHB, p. 190). Which is it?
(Below are some related Q&As, but not specific to versatile weapons, sadly).
The accepted answer to a related Q&A (thanks @NautArch) suggests that:
Taking your hand off the weapon should not require any action expenditure – you are just letting go of it, same as if you dropped it.
You can then use your free object interaction to restore your grip after casting.
The reasoning for the first case makes sense, but the second case isn’t backed up by anything, although I can see the logic behind it.
The errata posted in that answer, to me, suggests that it would in fact cost nothing to grip the weapon with a second hand, almost like it’s “part of the attack”, similar to how the Ammunition weapon property works, but again, this is logic, not RAW.
To give a concrete example, if we imagine that a PC’s turn starts with a longsword in one hand and a spellcasting focus in the other; they spend their bonus action casting a spell with their focus, and then spend their free object interaction putting that focus away. With only their action left, can they now attack with their longsword using it as a versatile weapon (i.e. dealing 1d10 damage instead of 1d8)?
See also, the “following round” scenario of this question (thanks @Medix2), which involves sheathing a shortsword and attacking with a longbow that requires two hands. This is almost exactly the same scenario as the one I detailed above.