#compsci #python # Properties ## Combinations You can mix numeric types, eg: ```python 40+3.14 # 43.14 ``` The rule is simple: Python first converts operands **up** to the type of the most complicated operand, and then performs the math on same-type operands. Python ranks the complexity of numeric types like so: (from the simplest to the most complicated) 1. Integers 2. Floating-point numbers 3. Complex numbers ## Operator overloading and polymorphism All Python operators may be overloaded (i.e. implemented) by [[Classes in Python|classes]] to work on objects you create. Furthermore, Python itself automatically overloads some operators: i.e. the + operators which sums numbers and concatenates sequences. This property is called [[Polymorphism in Python|polymorphism]] ## Display formats Due to the limitations of floating-point hardware, Python can display numbers differently, using **str()** and **repr()**: ```python num='Hello World' repr(num) # 'Hello World' str(num) # Hello World ``` repr() produces results that look as though they were code; str() converts to a typically more user-friendly format if available. Some objects have both. As seen in this example, these functions can be applied to other Python data types. ## Chained comparisons Python allows the user to chain their comparisons like this: ```python A