Python as a Calculator
||11 plus 56||67|
||23 minus 52||-29|
||4 multiplied by 5||20|
||2 to the power of 5||32|
||9 divided by 2||4.5|
||9 divided by 2||4|
||9 mod 2||1|
A type is a set of values and operations that can be performed on those values.
Two of Python's numeric types:
float: floating point number (an approximation to a real number)
Arithmetic Operator Precedence
When multiple operators are combined in a single expression, the operations are evaluated in order of precedence.
|*, /, //, %|
|+ (addition), - (subtraction)||lowest|
Syntax and Semantics
Syntax: the rules that describe valid combinations of Python symbols
Semantics: the meaning of a combination of Python symbols is the meaning of an instruction — what a particular combination of symbols does when you execute it.
A syntax error occurs when we an instruction with invalid syntax is executed. For example:
>>> 3) + 2 * 4 SyntaxError: invalid syntax
A semantic error occurs when an instruction with invalid semantics is executed. For example:
>>> 89.4 / 0 Traceback (most recent call last): File "", line 1, in 89.4 / 0 ZeroDivisionError: float division by zero