The luminosity function of galaxies is derived from a cosmological hydrodynamic simulation of a \Lam cold dark matter ( CDM ) universe with the aid of a stellar population synthesis model . At z = 0 , the resulting B band luminosity function has a flat faint end slope of \alpha \approx - 1.15 with the characteristic luminosity and the normalization in a fair agreement with observations , while the dark matter halo mass function is steep with a slope of \alpha \approx - 2 . The colour distribution of galaxies also agrees well with local observations . We also discuss the evolution of the luminosity function , and the colour distribution of galaxies from z = 0 to 5 . A large evolution of the characteristic mass in the stellar mass function due to number evolution is compensated by luminosity evolution ; the characteristic luminosity increases only by 0.8 mag from z = 0 to 2 , and then declines towards higher redshift , while the B band luminosity density continues to increase from z = 0 to 5 ( but only slowly at z > 3 ) .