python类定义小问题

1 >>> class Athlete:
2     def __init__ (self,a_name,a_dob=None,a_times=[]) :
3         self.name = a_name
4         self.dob = a_dob
5         self.times = a_times
6 
7         
8 >>> sarah =Athlete('Sarah Sweeney','2002-6-27',['2.65','2:56','1.45'])
9 >>> james = Athlete('James Jone')

1、__init__     左右各是两个小短下划线_ _

2、 def (空格) __init__ (self) : 没有空格会提示语法错误。

原文地址:https://www.cnblogs.com/xflqm/p/7437473.html