Python类与标准库

Python类

>>> class MyClass:
...     """A simple example class"""
...     i = 12345
...     def f(self):
...         return 'hello world'
... 
>>> MyClass.__doc__
'A simple example class'
>>> MyClass.i
12345
>>> h = MyClass()
>>> h.f()
'hello world'

操作操作系统

>>> import os
>>> os.getcwd()
'/home/jiqing'
>>> os.system('mkdir today');
0
>>> os.chdir('/home/wwwroot/default')
>>> os.getcwd()
'/home/wwwroot/default'

常用数学计算

>>> import math
>>> math.log(1024,2);
10.0
>>> import random
>>> random.choice(['apple','pear','banana'])
'banana'
>>> random.random()
0.8585164844368266
>>> random.random()
0.1898083053044728

猜你喜欢

转载自www.cnblogs.com/jiqing9006/p/9939397.html