The technical difference
A 301 status code tells the browser and the crawler: 'this URL has permanently moved; update your bookmarks and your index.' A 302 says: 'this URL has temporarily moved; come back to the original URL later.' Browsers cache 301s aggressively (often indefinitely) and rarely cache 302s. Crawlers treat 301 as a strong signal to drop the original URL from the index and consolidate signals onto the destination; 302 keeps the original URL in the index.
Google has documented that since around 2016 the ranking-signal transfer for 301 and 302 is more similar than it used to be (Google Search Central, 2016) — but the indexing behaviour still differs substantially.