python类

def Main():
    class A:
        pass

    a=A()
    a.x=1
    print a.x

if __name__=="__main__":
    Main()


#-*-coding:utf-8-*-
import sys
def Main():
    class A:
        def __init__(self):
            self.x=1

    a=A()
    print "a.x", a.x




class Student:
    def __init__(self,name,age,sex = 'male'):

        self.__name=name
        self.__age=age
        self.sex = sex
    def getName(self):
        format="my name is %s my age is %d"%(self.__name,self.__age)
        print format
    def __del__(self):
        print "del2222"
    #def __add__(self):
    #   print "add2234343422"
if __name__=="__main__":
    Main()
    student=Student("chu",35)
    student.getName()
    print "name", student.__name
    print "sex", student.sex

 

posted on 2016-08-06 18:06  与非朋仔  阅读(143)  评论(0编辑  收藏  举报

导航