Python Forum
Help with understanding the following code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with understanding the following code
#1
Hi everyone,

I am doing the Dataquest course and can’t really understand the following code. The following code is supposed to do capitalize every word and replace the gender with the string “Gender Unknown”

I don’t understand why the if not Gender will return True when the gender is empty. Can someone please explain to me

for row in moma:
    Gender = row[2]
    Gender = Gender.title()
    if not Gender:
        Gender = “Gender Unknown”
Reply
#2
Read following documentation: Truth value testing
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Because empty collections are treated as False. See the docs.
Reply
#4
Thanks for the quick response
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Please help in understanding this piece of code tinkalgo 9 4,505 May-10-2018, 04:32 PM
Last Post: tinkalgo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020