Shouldn't this give me an error?!

Screen Link:

My Code:

for row in moma:
    if row[5] == "":
        row[5] = "Gender Unknown/Other"
        row[5] = row[5].title()
    if row[2] == "":
        row[2] == "Nationality Unknown"
        row[2] = row[2].title()
    print(row[2], row[5])

What I expected to happen:
I expected to get an error due to line 7
row[2] == “Nationality Unknown”
What actually happened:
No error reported.
code run and I got the output

Replace this line with the output/error

American Male
German Male
Brazilian Male
British Male
French Male
American Gender Unknown/Other
Nationality Unknown Gender Unknown/Other
Colombian Male
American Male


No, the code will not give an error, as line 7 will evaluate to a boolean expression. In case you want to make sure, wrap the print function around line 7 i.e

print(row[2] == "Nationality Unknown")

Hope it helps!

Hi @veeral27596!

I agree there’s no syntax error, but the string "Nationality Unknown" shouldn’t be assigned to row[2], should it?

hi @otavios.s,

Not really sure, in what context this code is being used. Just wanted to clarify that there are no syntactical errors in the given code.

Yes, some context would be good. Can you post the screen link @4ruleoflaw?

But what a think is if if row[2] == "": is true, then row[2] == "Nationality Unknown" would just return a boolean value False, without anything being assigned…

1 Like

Thank you both for your answers.
As to context, the dataset, moma, is a list of lists … that I need to clean up … change the said fields to Title Case … if blank, assign given text …
see sample data below. I get your answer, as to why I shouldn’t get an error.
It was flawed thinking on my part .


[[‘Dress MacLeod from Tartan Sets’, ‘Sarah Charlesworth’, ‘American’, 1947, 2013, ‘Female’, ‘1986’, ‘Prints & Illustrated Books’], [‘Duplicate of plate from folio 11 verso (supplementary suite, plate 4) from ARDICIA’, ‘Pablo Palazuelo’, ‘Spanish’, 1916, 2007, ‘Male’, ‘1978’, ‘Prints & Illustrated Books’], [‘Tailpiece (page 55) from SAGESSE’, ‘Maurice Denis’, ‘French’, 1870, 1943, ‘Male’, ‘1889-1911’, ‘Prints & Illustrated Books’], [‘Headpiece (page 129) from LIVRET DE FOLASTRIES, À JANOT PARISIEN’, ‘Aristide Maillol’, ‘French’, 1861, 1944, ‘Male’, ‘1927-1940’, ‘Prints & Illustrated Books’], [‘97 rue du Bac’, ‘Eugène Atget’, ‘French’, 1857, 1927, ‘Male’, ‘1903’, ‘Photography’], [‘Pictorial ornament (folio 11) from WOODCUTS’, ‘Antonio Frasconi’, ‘American’, 1919, 2013, ‘Male’, ‘1957’, ‘Prints & Illustrated Books’]]

1 Like

I mean you shouldn’t get a syntax error, but I do not think your code was supposed to do what you expect from it. Can you post the link fro the mission please?