A contract in Solidity is a set of code written in the Solidity language that is deployed to the Ethereum blockchain. Contracts are immutable and can be used to create distributed applications (dApps). Contracts are self-executing and are typically used to facilitate digital transactions.
A library in Solidity is a set of code written in the Solidity language that is imported into a contract. Libraries are not deployed to the blockchain, but instead are used to add functionality to contracts. Libraries can be used to store and access data, perform calculations, and perform other tasks. For example, a library could be used to calculate the amount of Ether that needs to be transferred in a transaction.