I have difficulty understanding this line:
`if not gender`:
I believe it is checking for an empty string as per the condition :
ifstatement to check if the value is an empty string and, if so, give it a descriptive value.
So I read this as — if it is not true that the variable ‘gender’ = gender.title()
Is it looking at the content of — gender variable — ie ‘Male’ of ‘Female’ or only its type which I assume could only be string because of the title() method?
I am not entirely sure if it is saying:
- if not String?
if not ‘Male’/‘Female’
I read that empty strings are false by default so I think it would evaluate to
if not false/empty string and thereby be true but I do not see where the " "
in : if not " "
would come from since gender was assigned like this - gender = row and do not see empty strings in the dataset . Please advise.
for row in moma:
gender = row
# convert the gender to title case gender = gender.title() # if there is no gender, set # a descriptive value if not gender: gender = "Gender Unknown/Other" row = gender