Skip to content

Latest commit

 

History

History
63 lines (51 loc) · 3.58 KB

design.md

File metadata and controls

63 lines (51 loc) · 3.58 KB

Goal

This concept exercise should teach how basic non-customized comparisons work in python and how to use them effectively.

Learning objectives

  • understand all comparison operations in Python have the same priority and are evaluated after arithmetic, shifting, or bitwise operations.
  • understand all comparisons yield the boolean values True and False
  • know that identity comparisons is and is not are for checking an objects identity only
  • understand that == and != compare both the value & type of an object.
  • know where Python has altered the behavior of == and != for certain built-in types (such as numbers, or for standard library types like decimals, and fractions to allow comparison across and within type.
  • know that unlike numeric types, strings (str) and binary sequences (bytes & byte array) cannot be directly compared.
  • understand how comparisons work within built-in sequence types(list, tuple, range) and built-in collection types (set, [dict])
  • know about the "special" comparisons None, NotImplemented (comparing either should use identity operators and not equality operators because they are singleton objects) and NaN (NaN is never == to itself)
  • use the value comparison operators ==, >, <, != with numeric types
  • use the value comparison operators ==, >, <, != with non-numeric types
  • use is and is not to check/verify identity

Out of scope

  • rich comparison with __lt__, __le__, __ne__, __ge__, __gt__
  • understanding (and using the concept) that the == operator calls the dunder method __eq__() on a specific object, and uses that object's implementation for comparison. Where no implementation is present, the default __eq__() from generic object is used.
  • overloading the default implementation of the __eq__() dunder method on a specific object to customize comparison behavior.
  • set operations
  • performance considerations

Concepts

  • Comparison priority in Python
  • Comparison operators ==, >, <, !=
  • Identity methods is and is not
  • Equality applied to built-in types
  • Equivalence vs equality
  • Inequality

Prerequisites

  • basics
  • booleans
  • dicts
  • lists
  • sets
  • strings
  • tuples
  • numbers
  • iteration

Resources