Python - Chapter 3
Exponents vs. E-notation
Don't get confused between raising a number to a power (also called exponentiation) and E-notation.
Floating-point numbers (floats)
In computer programming, decimal numbers are also called floating-point numbers (floats). This is b/c the decimal point "floats" around.
Operators
+, -, *, /, %. These are called "operators" because they "operate on" the numbers around them.
Increment notation
>>> number = 7 >>> number += 1 >>> print number 8
Decrement notation
>>> number = 7 >>> number -= 1 >>> print number 6
Exponentiation
Arithmetic operator that raises to a power. Python uses a double star (asterisk) for exponents. For example, print 3 ** 5 ==> 243 Note: You can write exponents that are not integers. print 3**5.5
E-notation
One way to display very large or very small numbers is to use SCIENTIFIC NOTATION. Ex. 1: 3.8E16 or 3.8e16. Ex. 2: 1.752e-13.
Order of Operations (PEMDAS)
Parenthesis, Exponents, Multiplication, Division, Addition, Subtraction
If you enter two decimals,
Python thinks you want a decimal number for the answer.
If you enter two integers,
Python thinks you want an integer for the answer.
Increments and Decrements
These are done so often in programming that they have their own operators: += (increment) and -= (decrement)
Modulus (remainder)
a special operator for calculating the remainder for integer division. The symbol is the percent symbol (%). >>> print 7 % 2 1
The = sign is also an operator . . .
and it is called the ASSIGNMENT OPERATOR because it assigns a value to a variable.
Python uses the forward slash (/)
for division
Python uses the hyphen (-)
for subtraction
Python (and all other programming languages) follow
proper math rules and the order of operations.
Incrementing
score = score +1
Decrementing
score = score -1
Operands
the things being operated on.
If you want to change the order of operations to make something go first,
you must put parentheses around it.