main函数
import sklearn
import numpy as np
print(sklearn)
# print("hello")
ra = np.random.randn(5)
# print(ra)
def ss():
a = 1
b = 2
print(a+b)
pass
# ss()
def plot():
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)
plt.show()
if __name__ == '__main__':
# ss()
plot()
pass
if name == 'main': python主函数的入口,而在其中过程画的东西(函数,print语句等等...)也会被执行。
python 重新载入模块
>>>import importlib
>>>importlib.reload(foo)
3
Out[10]:
>>>foo.new()
This is new reload(hello)
类的编写
代码
class ClassCreat:
# 用这个方法控制如何初始化对象
def __init__(self, c_int, c_string, c_list=[]):
# 把含有默认值的参数放在了不含默认值的参数的前面
self.cint = c_int
self.clist = c_list
self.cString = c_string
pass
def read(self):
print(self.cint)
print(self.clist)
print(self.cString)
pass
pass
调用
>>importlib.reload(foo)
3
Out[18]:
>>cc = foo.ClassCreat(1,'string',[1,2,3,4,5])
>>cc.read()
1
[1, 2, 3, 4, 5]
string
>>cc = foo.ClassCreat(1,'string')
>>cc.read()
1
[]
string
错误
1.non-default argument follows default argument
把含有默认值的参数放在了不含默认值的参数的前面
2.TypeError: object() takes no parameters
对象没有初始化成功
把init写成了int
屏幕快照 2018-03-28 下午4.49.17.png