In the official Python speed tips wiki, it mentioned the following regarding class.member
:
Suppose you can't use map or a list comprehension? You may be stuck with the for loop. The for loop example has another inefficiency. Both newlist.append and word.upper are function references that are reevaluated each time through the loop. The original loop can be replaced with:
upper = str.upper
newlist = []
append = newlist.append
for word in oldlist:
append(upper(word))
What does "function references that are reevaluated each time" mean? Python re-interprets the function everytime class.member
is called?