Like most Mediterranean cities, Mexico City is relatively formal with strangers, and they vastly appreciate if and when you try to speak in Spanish – even a little Spanish.
That means before you do or say anything, in any transactional setting, and no matter how little Spanish you speak, simply say “Buenos días” if it’s before 11 AM, and “Buenas tardes” until it is truly night (11 AM until 6-8PM depending on the season). After nightfall, no sunlight at all, you should say “Buenas noches” and that lasts until 6 AM.*
This is a cultural thing that is ingrained in Mexico City people (and in most Mexicans).
Outside of buying things or preparing to buy something, you also need to say “Buenos días/Buenas tardes”:
*Mexico City residents will tell you that, officially, “Buenos días” changes to “Buenas tardes” at 12 PM,
but the very same Chilangos will stop saying “Buenos días” at 11 AM
and with very little awareness that they’ve done it. Just stick to 11 AM.
Again, from a strong Mediterranean influence, Mexico City is relatively formal compared to more northerly cultures and those influenced by such cultures.
With that in mind, no matter the time of year, it is not really the place to wear shorts or sandals or flip flops.
Mexico City residents may not say anything, but you may find your experience vastly improved by wearing long trousers, and closed-toe shoes or sneakers.