In this paper, several classes of two-weight or three-weight linear codes over Fp from quadratic or non-quadratic functions are constructed and their weight distributions are determined. From the constructed codes, we obtain some optimal linear codes with respect to the Singleton bound and the Griesmer bound. These two- or three-weight linear codes may have applications in secret sharing, authentication codes, association schemes and strongly regular graphs. © ...