EVERYTHING!!! The problem is that there IS NO SYNTAX!!!
There's plenty of syntax. In fact, there is something a lot like exactly the right amount for it to work - if there wasn't, it wouldn't.
The for loops are like 'For something in something. What the hell does that mean?
It means exactly what it sounds like, more or less. In many languages it would be a "foreach" instead of a "for", if it matters to you. Python for loops can loop over anything that is iterable, but it is typically a list.
When you go through the contents of your pocket looking for something do you create some integer and increment it and such, or do you just do something a lot like "for thing in MyPocket" and examine each thing?
In C++, for loops are nice and simple.
Code:
for (int i = 0; i < GC.getNumUnitInfos(); i++)
{
}
That isn't particularly simple. In fact, the only reason it seems to be simple to you is that you know what it means. You have to know the secret to the magic to get it to work. Specifically you have to know that there are 3 separate things inside the parenthesis of the for loop each of which is an expression of some sort, separated by semicolons, and what each of the 3 is used for (they aren't even the same kind of expression, the middle one is a boolean and the other two aren't). Only simple if you know the magic. If you didn't know, it would make no sense to you.
The equivalent in Python would be
Code:
for i in range(gc.getNumUnitInfos()):
blah
blah
blah
The magic part of that is in knowing what the range function does: when it has one argument, it returns a list of integers with the specified number of elements in it which starts with 0 and increases with an increment of 1 (you can specify more parameters to change these characteristics). So from range(3) you get the list [0,1,2].
or
Code:
CvCity* pCity;
for (pCity = firstCity(); pCity != NULL; pCity = nextCity())
{
}
The equivalent in Python, because of the way the city list is accessed in the Civ4 Python API (assuming you have a variable "player" which is a CyPlayer type object, a detail you left out of your example - presumably you'd intend to use the above loop in a function inside the CvPlayer class since it wouldn't work as-is anywhere else, unless some other object keeps a list of cities like that):
Code:
(loopCity, iter) = player.firstCity(false)
while(loopCity):
blah
blah
blah
(loopCity, iter) = player.nextCity(iter, false)
Which, technically, isn't even a for loop, it is a while loop. It's the equivalent of the C++ version which goes like so:
Code:
CvCity* pCity;
pCity = firstCity();
while (pCity != NULL)
{
blah;
blah;
blah;
pCity = nextCity();
}
Also, in python, there's no type specifiers, so you never know what something is! And sometimes you can't tell if you're creating an object or calling a function!
If you don't know what something is, you should have payed more attention to what it was when you made it. It doesn't magically change what it is, it only changes if you change it. But that is why the Civ Python code uses the notation it does, so that you can know what the intended usage is: iPlayer is an integer, pPlayer is not (the "p" was apparently selected to match the C++ code where it uses pointers to the objects, but in the Python it is pretty much the object - although technically, behind the scenes, every variable in Python is a pointer since it does everything by reference, not by value, just in case you wanted to know).
And creating an object is calling a function (possibly more than one), specifically it's constructor and/or initializer (whatever terminology you want to use). That's true in C++ too.
Functions generally return objects of one sort or another, so the difference is pretty small.
What's the difference between calling a function that does calculation X and returns the data in the fields of a MyFoo type object (that it must have either created or received as an argument or from somewhere else) and creating a MyFoo type object who's initialization function does calculation X and sets its fields accordingly?
If you weren't sufficiently confused before, maybe you are now...