2010年12月7日 星期二

[Python] Math and Random 速記

>>> import math
>>> math.pi
3.141592653589793
>>> math.sqrt(85)
9.219544457292887
>>> import random
>>> random.random()
0.7685885105411999
>>> random.choice([1,2,3,4])
2
>>>

Reference:
math — Mathematical functions
random — Generate pseudo-random numbers
Learning Python, 3e
Related Posts Plugin for WordPress, Blogger...