Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # MATH
  2.  
  3. ## basic operations
  4. ```python
  5. 10 + 4 # add (returns 14)
  6. 10 - 4 # subtract (returns 6)
  7. 10 * 4 # multiply (returns 40)
  8. 10 ** 4 # exponent (returns 10000)
  9. 10 / 4 # divide (returns 2 because both types are 'int')
  10. 10 / float(4) # divide (returns 2.5)
  11. 5 % 4 # modulo (returns 1) - also known as the remainder
  12.  
  13. ```
  14.  
  15. ### force '/' in Python 2.x to perform 'true division' (unnecessary in Python 3.x)
  16. ```python
  17. from __future__ import division
  18. 10 / 4 # true division (returns 2.5)
  19. 10 // 4 # floor division (returns 2)
  20. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement