Following The New Boston on youtube, he is using is in an if statement and doesnt show any error, on mine I get a syntax warning and it asks if I meant ==, but still displays the output the way it should be.

Recommended Answers

Have you tried the tutorials code verbatim?

Can you show the code in question?

Jump to Post

One thing to remember is that in python formatting matters. This site has a code editor to help you format your code. The button is titled Code Block and looks like this, </>.

def get_gender(sex='unknown'):
    if sex is "m":
        sex = 'Male'
    elif sex is 'f':
        sex = 'Female'
    print(sex) …
Jump to Post

Did some more research on this. It appears the tutorial was written using python 3.4. The syntax warning is new with python 3.8. I would suggest that this is why the tutorial doesn't show a warning.

Jump to Post

All 4 Replies

Re: pycharm syntax warning when I use "is" instead of == 80 80

Have you tried the tutorials code verbatim?

Can you show the code in question?

Re: pycharm syntax warning when I use "is" instead of == 80 80

def get_gender(sex='unknown'):
if sex is "m":
sex = 'Male'
elif sex is 'f':
sex = 'Female'
print(sex)
get_gender('m')
get_gender('f')
get_gender()

Re: pycharm syntax warning when I use "is" instead of == 80 80

One thing to remember is that in python formatting matters. This site has a code editor to help you format your code. The button is titled Code Block and looks like this, </>.

def get_gender(sex='unknown'):
    if sex is "m":
        sex = 'Male'
    elif sex is 'f':
        sex = 'Female'
    print(sex)
get_gender('m')
get_gender('f')
get_gender()

That being said, do you have the link to the tutorial?

This code will always give you that warning. Basically:

is is for comparing whether 2 objects reference the same area in memory.

== is for comparing whether 2 objects hold the same value(s)

Re: pycharm syntax warning when I use "is" instead of == 80 80

Did some more research on this. It appears the tutorial was written using python 3.4. The syntax warning is new with python 3.8. I would suggest that this is why the tutorial doesn't show a warning.

commented: Thank you very much!! +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.