# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#http://blog.chinaunix.net/uid-22521242-id-4081674.html



#一个关于类的案例

class People():
    #定义基本属性
    name=''
    age=0
    #定义私有属性,私有属性无法在类的外部直接访问
    __weight=0
    #定义构造方法
    def __init__(self,n,a,w):
        self.name=n
        self.age=a
        self.__weight=w

    def speak(self):
        print self.name,self.age


if __name__=='__main__':
    p=People('xiaodeng',28,150)
    p.speak()#xiaodeng 28

 

相关文章:

  • 2022-12-23
  • 2019-11-07
  • 2021-09-26
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2021-07-31
  • 2021-10-13
  • 2022-01-09
  • 2022-03-03
相关资源
相似解决方案