So, first of all you have the array of types, which each have an index (from 0, to however many items you have in the array - 1, because it started at 0, not 1) e.g.
summonTypes = ["archer", "soldier", "peasant", "paladin"]
0 1 2 3
So len(hero.built)%len(summonTypes) will always return a result within 0-3.
We know that len(summonTypes) will always equal 4, because the number of items in the array won’t change in this level. So that side of the operation is fixed.
len(hero.built) on the other hand will increase from 0 to however many units you build.
Finally, let’s look at the most important bit, the % (modulo) operator. What % does is it returns the remainder of a division. Here the division is len(hero.built) divided by len(summonTypes). So you find out how many times len(summonTypes) can go into len(hero.built), then return the gap between that number, and what len(hero.built) actually is.
For example, imagine you haven’t built any troops.
So len(hero.built) is 0, and, or course, len(summonTypes) is 4.
So, % will find the remainder of 0 divided by 4. 0 divided by 4 is 0 and has no remainder, so that means it will return 0, which is “archer”.
Next time you have enough gold to summon something, len(hero.built) will be 1, and len(summonTypes) will still be 4.
So 1 divided by 4 is what? 4 goes into 1 zero times, with a remainder of 1. So the modulo function will return 1, which is “soldier”.
I hope this helps you understand it.