4. • Comparisons to singletons like None should always be
done with is or is not , never the equality operators.
• Also, beware of writing if x when you really mean if x is
not None
• -- e.g. when testing whether a variable or argument that
defaults to None was set to some other value. The other
value might have a type (such as a container) that could
be false in a boolean context!
PEP8 – Programming Recommendations
4
5. • Don't compare boolean values to True or False
using == .
• Yes: if greeting:
• No: if greeting == True:
• Worse: if greeting is True:
PEP8 – Programming Recommendations
5
6. • Singleton을 비교할 때는 “is”나 “is not” 을 사용한다.
PEP8 – Programming Recommendations
6
7. • “==” 나 “!=” 는 사용하지 않는다.
PEP8 – Programming Recommendations
7
8. • “if x” 가 “if x is not None” 인지 “if x is True 인지 구분한다.
• boolean 형식에서 False 인 자료형이 있을 수 있다.
PEP8 – Programming Recommendations
8
9. • Boolean 값을 “==” 를 사용해서 True, False 로 비교하지
않는다.
PEP8 – Programming Recommendations
9
25. • Since there is only one None object, equality can be tested
with identity.
• Identity tests are slightly faster than equality tests.
• Also, some object types may overload comparison, so equa
lity testing may be much slower.
• if v == None --> if v is None:
• if v != None --> if v is not None:
PEP290 – Testing for None
25
26. • Since there is only one None object, equality can be tested
with identity.
PEP290 – Testing for None
26
27. • Identity tests are slightly faster than equality tests.
• Also, some object types may overload comparison, so equa
lity testing may be much slower.
• if v == None --> if v is None:
• if v != None --> if v is not None:
PEP290 – Testing for None
27
33. t h a n k y o u
Copyright 2016 Penta Security Systems Inc. All rights reserved.
KOREA
U.S.A.
JAPAN
Yeouido, Seoul www.pentasecurity.com (HQ)
Houston, Texas www.pentasecurity.com/en
Shinjuku-Ku, Tokyo www.pentasecurity.co.jp