Using same variable name and Equal sign

Hello,
I had a question on for the “Python and Preparing Data in Python” lesson. Below this is what I have:

for row in moma:
nationality = row[2]
nationality = nationality.replace("(", “”)
nationality = nationality.replace(")", “”)
row[2] = nationality

I had two questions: 1) What is the difference between typing “row[2] = nationality” vs. “nationality = row[2]” and 2) “nationality” is used numerous times here. I thought you could only use that name for a variable once. Could you explain why we can use it more than once here and everything is OK? Thank you!

Hi @mtl1212:

In future, please provide a question link and format your code as per these guidelines.

The first is assigning the value stored in nationality back to index 2 of each row. We do this after our data cleaning (i.e. removing the round brackets. The second is initially assigning the value stored in row[2] when we are interating over the moma dataset to the variable nationality.

Not necessarily. In this case we wish to “clean” our data so we store the cleaned value back to the original position (i.e. the same row and column).

Hope this clarifies

Thank you. I keep forgetting the “=” is an assignment operator and not equality! Glad to know about the multi-usage of variables in regards to cleaning data.

No worries @mtl1212. Happy learning!