Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MATH
- ## basic operations
- ```python
- 10 + 4 # add (returns 14)
- 10 - 4 # subtract (returns 6)
- 10 * 4 # multiply (returns 40)
- 10 ** 4 # exponent (returns 10000)
- 10 / 4 # divide (returns 2 because both types are 'int')
- 10 / float(4) # divide (returns 2.5)
- 5 % 4 # modulo (returns 1) - also known as the remainder
- ```
- ### force '/' in Python 2.x to perform 'true division' (unnecessary in Python 3.x)
- ```python
- from __future__ import division
- 10 / 4 # true division (returns 2.5)
- 10 // 4 # floor division (returns 2)
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement