Welcome to Stack Overflow! Let's take a look at what's happening. I've added links to further reading along the way, do take a look at them before asking further questions.
for incident in soup('td', width="90%"):
incident
is just an arbitrary local variable for the iterable returned by soup
. Generally speaking, the local variable in a for
statement is probably a list, but may be a tuple or even a string. If it's possible to iterate over something, like a file, then Python will probably accept for
to go through the items.
In this case, soup
is returning a list of td
HTML elements with a width of 90%. We can see this because of what happens on the next line:
where, linebreak, what = incident.contents[:3]
where
, linebreak
and what
are all arbitrary local variables as well. They are all being assigned in a single statement. In Python, this is known as multiple assignment. Where do those three elements come from?incident.contents[:3]
is asking for the first three elements, using slice notation.
print where.strip()
print what.strip()
These two lines print where
and what
onto the screen.¹ But what is strip
doing? It's removing white space. So, " some text "
become "some text"
.
break
break
is just breaking the for
loop after its first cycle. It doesn't break the whole program. Instead, it returns the program's flow to the next line after the loop.
print 'done'
This is just doing what it says, sending the words 'done' to the screen. If you are using this program, you know it is complete when you see 'done' (without the quotes) appear on the screen.
¹ To be more technically precise, they send the bytes to standard out (normally known as stdout).