You're correct; for operator in ["+-", "*/"]:
means operator will be "+-"
the first time through and "*/"
the second time through the loop.
Notice how later it checks if strinput[p] in operator
. Python treats a string as a list of characters, so this expression will only be true if strinput[p]
is equal to "+"
or "-"
on the first time through and "*"
or "/"
the second time through.
(The reason they do this is for order of operations- "+"
and "-"
get equal but lower precedence to "*"
and "/"
)