Many classes: bard, ranger, sorcerer, and warlock have this type of text in their Spellcasting or Pact Magic feature under Spells Known of 1st Level or Higher:
Additionally, when you gain a level in this class, you can choose one of the spells you know and replace it with another spell from the spell list, which also must be of a level for which you have spell slots.
Can I choose to replace cantrips or only spells of 1st level or higher?
Best Answer
RAW: No*, you can only replace spells of 1st level or higher
*Unless you use optional rules from Tasha's Cauldron of Everything, see down below.
That section only applies to spells of 1st level or higher (context matters)
For the sorcerer, ranger, bard, and warlock the sentence above is under the section Spells Known of 1st Level and Higher.
The phrase must be interpreted with that context. When read this way it is clear that when it says "one of the spells you know" it is implied that it means only those 1st level and higher. There is a cantrip section immediately above that one which does not have any such wording.
Both the old and the new spell must be ones that use spell slots (and cantrips don't)
Additionally, the phrasing implies that both the spell to be replaced and the one that it is being replaced with must use spell slots:
The implication being that the spell that is being replaced is already at a spell level for which you have spell slots. The reason they don't say this more explicitly is likely because of the context of it being under a section that is only talking about spells of 1st level or higher. And cantrips, despite being 0 level spells, don't use spell slots:
Rules as Intended: Cantrips are not intended to be replaced
This also seems to follow designer guidance/intent as Jeremy Crawford says explicitly here:
Jeremy Crawford has also explained intent more generally:
Narrative reason: Cantrips are special
The narrative reason for this is likely because cantrips are different from spells in that:
Jeremy Crawford seems to support this narrative as well:
Tasha's optional rules
Tasha's Cauldron of Everything includes new optional class features that allow for the swapping of cantrips. The exact method varies from class to class. For example, the Wizard's Cantrip Formulas says: