Learning in Python:Chapter 5 Numeric Types

 1.  Built-in Numeric Tools

  • Expression operators: +, -, *, /, >>, **, &, etc.
  • Built-in mathematical functions: pow, abs, round, int, hex, bin, etc.
  • Utility Modules: random, math, etc.
2.  Expression Operaters
 

 Learning in Python:Chapter 5 Numeric Types

  • Ternary selection:  x if y else z
  • Slicing:  x[i:j:k]
3.  Other build-in Numeric Tools
  • import math
    • math.pi, math.e
    • math.sin(), math.cos(), math.tan()
    • math.sqrt()
    • math.floor(), math.trunc()
  • import random
    • random.random()
    • random.randint(1, 10)
    • random.choice()
  • pow(), abs(), sum(), min(), max(), round()
  • '%.1f' % 2.567, '{0:.2f}'.format(2.567)
4.  Other Numeric Types
  • Decimal
  • Fraction
  • Sets
    • Unordered, immutable
    • x = set('abcde')
    • member: 'e' in x
    • difference: x - y
    • union: x | y
    • intersection: x & y
    • symmetric difference: x ^ y

你可能感兴趣的:(python)