When I try this code in Python 2.7.3:
names = ["Paul", "Mary", "Susan"] names.sort() def valuate(string): print ord('A') return sum(ord(s) for s in string) i = 1 for name in names: print i, name, valuate(name) i += 1 I expect the output:
65 1 Mary 409 65 2 Paul 402 65 3 Susan 522 But instead I get:
1 Mary 65 409 2 Paul 65 402 3 Susan 65 522 It seems the print statement outputs the i and name values before calling the function. Is that so? Why?
printbecame a function, it works the way this OP expected.