SlideShare a Scribd company logo
1 of 33
Equality, Identity
2017. 3. 15
WAPPLES개발부 | 심경섭
==, is, !=, is not, None
I. PEP 8
II. The “is None” Idiom
III. “is” cost
IV. Equality, Identity
V. PEP 290
VI. Conclusion
목차
PEP 8
• 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
• 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
• Singleton을 비교할 때는 “is”나 “is not” 을 사용한다.
PEP8 – Programming Recommendations
6
• “==” 나 “!=” 는 사용하지 않는다.
PEP8 – Programming Recommendations
7
• “if x” 가 “if x is not None” 인지 “if x is True 인지 구분한다.
• boolean 형식에서 False 인 자료형이 있을 수 있다.
PEP8 – Programming Recommendations
8
• Boolean 값을 “==” 를 사용해서 True, False 로 비교하지
않는다.
PEP8 – Programming Recommendations
9
The “is None” Idiom
• “X == None” 대신 “X is None” 을 사용하는 제안은 꽤 오래
전부터 시작되었다.
The “is None” Idiom
11
• 거의 10년 동안 Python Community 에서는 위와 같은 비교
방식이 공식 처럼 사용되었다.
The “is None” Idiom
12
• “X is None” 은 현재 Python Idiom 으로 고려되고있다.
The “is None” Idiom
13
“is” cost
• 일부 소수의 프로그래머만 “is” 연산자를 사용하려 한다.
“is” cost
15
“is” cost – Identical object
16
• “is” 연산자는 동일 object의 비교에서 항상 True 를 보장하
지 않는다.
“is” cost – Identical object
17
• 이 동작은 구현에 따라 달라지게 된다.
“is” cost – Identical object
18
“is” cost – Semantic confusion
19
• 첫번째 코드는 “is not” 연산자를 사용 한 것이다.
• 두번째 코드는 “is” 와 “not” 연산자를 각각 사용한 것이다.
• Python 에서 유일하게 두 단어로된 연산자이다.
“is” cost – Semantic confusion
20
Equality, Identity
• Identity
• A variable holds the same instance as another variable.
Equality, Identity
22
• Equality
• two distinct objects can be used interchangeably. they often ha
ve the same id.
Equality, Identity
23
PEP 290
• 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
• Since there is only one None object, equality can be tested
with identity.
PEP290 – Testing for None
26
• 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
Conclusion
• 동일함을 확인할땐 “==” 연산자 보단 “is” 연산자를 사용하자
Conclusion
29
• “is” 연산자를 사용할 때, None 비교와 True/False 비교를 주
의하자
Conclusion
30
• None 을 비교할 때는 “is”나 “is not” 을 사용하자
Conclusion
31
• 사용하는 언어에 대해 관심을 가지고 잘 사용하자
Conclusion
32
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

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Python comparing

  • 1. Equality, Identity 2017. 3. 15 WAPPLES개발부 | 심경섭 ==, is, !=, is not, None
  • 2. I. PEP 8 II. The “is None” Idiom III. “is” cost IV. Equality, Identity V. PEP 290 VI. Conclusion 목차
  • 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
  • 11. • “X == None” 대신 “X is None” 을 사용하는 제안은 꽤 오래 전부터 시작되었다. The “is None” Idiom 11
  • 12. • 거의 10년 동안 Python Community 에서는 위와 같은 비교 방식이 공식 처럼 사용되었다. The “is None” Idiom 12
  • 13. • “X is None” 은 현재 Python Idiom 으로 고려되고있다. The “is None” Idiom 13
  • 15. • 일부 소수의 프로그래머만 “is” 연산자를 사용하려 한다. “is” cost 15
  • 16. “is” cost – Identical object 16
  • 17. • “is” 연산자는 동일 object의 비교에서 항상 True 를 보장하 지 않는다. “is” cost – Identical object 17
  • 18. • 이 동작은 구현에 따라 달라지게 된다. “is” cost – Identical object 18
  • 19. “is” cost – Semantic confusion 19 • 첫번째 코드는 “is not” 연산자를 사용 한 것이다. • 두번째 코드는 “is” 와 “not” 연산자를 각각 사용한 것이다.
  • 20. • Python 에서 유일하게 두 단어로된 연산자이다. “is” cost – Semantic confusion 20
  • 22. • Identity • A variable holds the same instance as another variable. Equality, Identity 22
  • 23. • Equality • two distinct objects can be used interchangeably. they often ha ve the same id. Equality, Identity 23
  • 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
  • 29. • 동일함을 확인할땐 “==” 연산자 보단 “is” 연산자를 사용하자 Conclusion 29
  • 30. • “is” 연산자를 사용할 때, None 비교와 True/False 비교를 주 의하자 Conclusion 30
  • 31. • None 을 비교할 때는 “is”나 “is not” 을 사용하자 Conclusion 31
  • 32. • 사용하는 언어에 대해 관심을 가지고 잘 사용하자 Conclusion 32
  • 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