The lac operon is one of the best known gene regulatory circuits and constitutes a landmark example of how bacteria tune their metabolism to nutritional conditions. It is nearly ubiquitous in Escherichia coli strains justifying the use of its phenotype, the ability to consume lactose, for species identification. Lactose is the primary sugar found in milk, which is abundant in mammals during the first weeks of life. However, lactose is virtually non-existent after the weaning period, with humans being an exception as many consume dairy products throughout their lives. The absence of lactose during adulthood in most mammals and the rarity of lactose in the environment, means that the selective pressure for maintaining the lac operon could be weak for long periods of time. Despite the ability to metabolize lactose being a hallmark of E. coli’s success when colonizing its primary habitat, the mammalian intestine, the selective value of this trait remains unknown in this ecosystem during adulthood. Here we determine the competitive advantage conferred by the lac operon to a commensal strain of E. coli when colonizing the mouse gut. We find that its benefit, which can be as high as 11%, is contingent on the presence of lactose in the diet and on the presence of other microbiota members in the gut, but the operon is never deleterious. These results help explaining the pervasiveness of the lac operon in E. coli, but also its polymorphism, as lac-negative E. coli strains albeit rare can naturally occur in the gut.