Guided project :why does == not work?

Screen Link:

My Code:


for row in hn:
    if title.lower()==title.startswith('ask hn'):
    elif title.lower()==title.startswith('show hn'):
Replace this line with your code

What I expected to happen:
I was expecting this to work, because title.lower()==title.startswith(‘ask hn’) translates to ‘ask hn’=‘ask hn’, if I’m not wrong

What actually happened:
Does not give the result, I was expecting. I tried debugging using the below code. But it does not return anything.

for row in hn:


if title.lower()==title.startswith('ask hn'):
Replace this line with the output/error

In short

  1. if title.lower().startswith(‘ask hn’): # works
  2. if title.lower()==title.startswith(‘ask hn’) # but this does not, in theory this is same as if title.lower().startswith(‘ask hn’) right ?
1 Like

You have a good thought process going on, but you’re not quite there yet.


Will return the title with everything in lower case.

title.lower().startswith(‘ask hn’)

will return a boolean value. It will return either True or False depending on whether the title.lower() starts with "ask hn" or not.

So, when you try to do -

if title.lower()==title.startswith('ask hn'):

you are trying to do -

if title.lower()==False:

The above is trying to check if a string is equal to the boolean False.

In Python, the above won’t throw an error, but it will return a False. Because the string and the boolean are not the same.

So, as you ask -

No, they are not the same in theory.

Thank you for the quick and clear explanation !.
It makes sense now.