For instance, the sorcerer's Spellcasting feature (PHB p. 101) says:
Spells Known of 1st Level and Higher
[...] The Spells Known column of the Sorcerer table shows when you learn more sorcerer spells of your choice. Each of these spells must be of a level of which you have spell slots. [...]
Additionally, when you gain a level in this class, you can choose one of the sorcerer spells you know and replace it with another spell from the sorcerer spell list, which also must be of a level for which you have spell slots.
Can I both learn a 4th-level spell and replace a 1st-level spell with another 4th-level spell, even if I only have one 4th-level spell slot as a 7th-level sorcerer?