定义类/实例

 

#!/usr/bin/python
# -*- coding: utf-8 -*-
'its a class test'
__author__ = 'mm_obj'

#定义名为Stu的类
class Stu(object):
  #define Stu property
  def __init__(self,name,age,gender):
    self.name=name
    self.age=age
    self.gender=gender
  #define Stu method age
  def p_stu_age(self):
    print '%s \'s age is:%d' % (self.name,self.age)

  #define Stu method name age gender
  def p_stu_ag(self):
    print '%s \'s age is:%d,gender is:%s' % (self.name,self.age,self.gender)

  def p_stu_name(self):
    print '%s' % (self.name)



Lily=Stu('Lily',20,'female')
Lucy=Stu('Lucy',25,'female')
#Print Lily.p_stu_age()
#print Lily.p_stu_ag()

#Lily.age=26
#print Lily.p_stu_ag()


#获取Stu类下的所有实例
import gc
for obj in gc.get_objects():
    if isinstance(obj,Stu):
        print obj.name

 

你可能感兴趣的:(定义类/实例)