In python, I know that it is permissible to write:
happy_bag = list()
if not (key in happy_bag):
print(key, " ain't in da bag.")
But would it also be okay to write:
happy_bag = list()
if key not in happy_bag:
print(key, " ain't in da bag.")
Also, the following is legal:
if key in happy_bag:
print("Congratulations! you have a ", key, " in your bag!")
But is it alright if we add the word "is"?
if key is in happy_bag:
print("Congratulations! you have a ", key, " in your bag!")
It is perfectly correct to write:
And it is even advised. From PEP 8: Programming conventions
regarding your second question
is in
is not a correct operator in python. The operatoris
is used to test reference identity: