Humans live in diverse, complex niches where survival and reproduction are conditional on the acquisition of knowledge. Humans also have long childhoods, spending more than a decade before they become net producers. Whether the time needed to learn has been a selective force in the evolution of long human childhood is unclear, because there is little comparative data on the growth of ecological knowledge throughout childhood. We measured ecological knowledge at different ages in Pemba, Zanzibar (Tanzania), interviewing 93 children and teenagers between 4 and 26 years. We developed Bayesian latent-trait models to estimate individual knowledge and its association with age, activities, household family structure and education. In the studied population, children learn during the whole pre-reproductive period, but at varying rates, with the fastest increases in young children. Sex differences appear during middle childhood and are mediated by participation in different activities. In addition to providing a detailed empirical investigation of the relationship between knowledge acquisition and childhood, this study develops and documents computational improvements to the modelling of knowledge development.