2008-06-19 13:02:10 / python交流
最近碰到两个Python的问题一时解决不了,想请教各位大侠1) 类的私有变量class Test:def __init__(self):self.__c = 'c'test = Test()test.__c是不能直接访问的,但是一旦给这个私有变量赋值之后又可以直接访问了,不知道是为什么啊。>>> class Test:def __init__(self):self.__c = 'c'>>> test = Test()>>> test.__cTraceback (most recent call last):File "", line 1, intest.__cAttributeError: Test instance has no attribute '__c'>>> test.__c = 'd'>>> test.__c2) ...
查看(187)
评论(23)