代码语言:javascript复制
test2.py文件:
test=1
print("我在类外,test值是:%s"%test)
class Test2(object):
test = 2
print("我在类里,test值是:%s"%test)
def __init__(self):
test=3
self.test=4
print("我在构造函数里,test值是:%s,selftest值是:%s"%(test,self.test))
def test2(self):
self.test = 5
test=6
print("我在方法里,test值是:%s,selftest值是:%s"%(test,self.test))
if __name__ == '__main__':
test=Test2()
test.test2()
test1.py文件:
一、执行了类外和类里的东西
from Test.test02 import Test2
"C:Program FilesPython35python.exe" C:/Users/wangli/PycharmProjects/Test/Test/test01.py
我在类外,test值是:1
我在类里,test值是:2
Process finished with exit code 0
二、执行了类外、类里、构造函数
from Test.test02 import Test2
test=Test2()
"C:Program FilesPython35python.exe" C:/Users/wangli/PycharmProjects/Test/Test/test01.py
我在类外,test值是:1
我在类里,test值是:2
我在构造函数里,test值是:3,selftest值是:4
Process finished with exit code 0
三、执行了类外、类里、构造函数、实例方法
from Test.test02 import Test2
test=Test2()
test.test2()
"C:Program FilesPython35python.exe" C:/Users/wangli/PycharmProjects/Test/Test/test01.py
我在类外,test值是:1
我在类里,test值是:2
我在构造函数里,test值是:3,selftest值是:4
我在方法里,test值是:6,selftest值是:5
Process finished with exit code 0