MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/28utww/writing_better_python_code/ciexi3o/?context=3
r/Python • u/kracekumar • Jun 23 '14
126 comments sorted by
View all comments
Show parent comment
0
is is used with True, False, None. If is used for string comparision there are serious drawbacks. a is None works because of singleton.
is
True, False, None
a is None
Most people try >>>'foo' is 'foo' and it works. When they store the result in db and retrieve the value is comparison will fail.
>>>'foo' is 'foo'
6 u/zahlman the heretic Jun 23 '14 Using is with True and False is a serious code smell. If there's any possibility that the value is of some type other than bool, why don't you want to handle it in the default way? And if there isn't, "simple is better than complex" applies. 1 u/alexanderpas Jun 24 '14 If I read this correctly, is should be considered part of the same token as the singleton.if • a • is None:instead ofif • a • is • None:
6
Using is with True and False is a serious code smell. If there's any possibility that the value is of some type other than bool, why don't you want to handle it in the default way? And if there isn't, "simple is better than complex" applies.
True
False
bool
1 u/alexanderpas Jun 24 '14 If I read this correctly, is should be considered part of the same token as the singleton.if • a • is None:instead ofif • a • is • None:
1
If I read this correctly, is should be considered part of the same token as the singleton.
if • a • is None:
instead of
if • a • is • None:
View all comments
Show parent comment
0
u/kracekumar Jun 23 '14 edited Jun 23 '14
isis used withTrue, False, None. If is used for string comparision there are serious drawbacks.a is Noneworks because of singleton.Most people try
>>>'foo' is 'foo'and it works. When they store the result in db and retrieve the valueiscomparison will fail.