If your task is to count the exact number of steps, then yes, print
would count as a step. But note also that your second print
is at least three steps long: list access, addition, and print.
In fact, print
(and other 'atomic' statements) might actually be worth many "steps", depending on how you interpret step, e.g., CPU cycles, etc. This may be overkill for your assignment, but to be accurate, it might be worth having a look at the generated byte code. Try this:
import dis
print dis.dis(function)
This will give you the full list of more-or-less atomic steps in your function, e.g., loading a function, passing arguments to that function, popping elements from the stack, etc. According to this, even your first print
is worth three steps (in Python 2.6):
2 0 LOAD_CONST 1 ('Hello')
3 PRINT_ITEM
4 PRINT_NEWLINE
How to interpret this: The first number (2
) is the line number (i.e., all the following instructions are for that line alone); the central numbers (0
) are jump labels (used by, e.g., if-statements and loops), followed by the actual instructions (LOAD_CONST
); the right column holds the arguments for those instructions ('Hello'
). For more details, see this answer.