'''
Created on 2011-4-30

@author: xuqiang
'''

class Student:
    
# attribute 
    i = 12345;
    
    
# member function
    def func(self):
        
print('in class member function : func');
    
    
# init
    def __init__(self):
        
print("in __init__ function");
        
        
# class instance
stu = Student();
stu.func();

class Complex :
    
# init 
    def __init__(self, real, img):
        self.real 
= real;
        self.img 
= img;
    
    
    
# operator
    def add(self, other):
        
return Complex(self.real + other.real, 
                       self.img 
+ other.img);

c1 
= Complex(11);
c2 
= Complex(11);
c3 
= c1.add(c2);
print(c3.img);

# empty class object
class Employee :
    
pass

class MyClass:
    
"""  a simple class example """
    i 
= 123456;
    
    
def f(self):
        
return 'hello world';


= MyClass();
print(c.f());


class Base:
    
"""  base class """
    
def __init__(self):
        
print("in base init.");
    
    
def override_func(self):
        
print("in base : overrride_func");
    
class Sub(Base):
    
def __init__(self):
        
print("in sub init");

    
def override_func(self):
        
print("in sub : override_func");

= Sub();
s.override_func();

if isinstance(s, Sub):
    
print("s is an instance of class Sub");

if issubclass(Sub, Base):
    
print("Sub is a sub class of class Base");
    

相关文章:

  • 2021-06-24
  • 2021-10-22
  • 2021-11-15
  • 2021-09-25
  • 2022-02-07
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2021-09-16
  • 2021-05-30
  • 2022-02-12
  • 2021-05-29
  • 2021-12-09
  • 2021-07-28
相关资源
相似解决方案