Python-100-Days/Day01-15/code/Day08/hack.py

26 lines
410 B
Python
Raw Normal View History

2018-04-27 00:00:22 +08:00
"""
另一种创建类的方式
Version: 0.1
Author: 骆昊
Date: 2018-03-08
"""
def bar(self, name):
2019-05-03 21:17:36 +08:00
self._name = name
2018-04-27 00:00:22 +08:00
def foo(self, course_name):
2019-05-03 21:17:36 +08:00
print('%s正在学习%s.' % (self._name, course_name))
2018-04-27 00:00:22 +08:00
def main():
2019-05-03 21:17:36 +08:00
Student = type('Student', (object,), dict(__init__=bar, study=foo))
stu1 = Student('骆昊')
stu1.study('Python程序设计')
2018-04-27 00:00:22 +08:00
if __name__ == '__main__':
2019-05-03 21:17:36 +08:00
main()