This is a book on optimal control problems (OCPs) for partial differential equations (PDEs) that evolved from a series of courses taught by the authors in the last few years at Politecnico di Milano, both at the undergraduate and graduate levels. The book covers the whole range spanning from the setup and the rigorous theoretical analysis of OCPs, the derivation of the system of optimality conditions, the proposition of suitable numerical methods,...