1.class Complex:
def __init__(self, realpart, imagpart):
self.r = realpart
self.i = imagpart
x = Complex(3.0,-4.5)
print(x.r, x.i)
2.class Complex:
def __init__(self, realpart, imagpart):
self.r = realpart
self.i = imagpart
def __del__(self):
print("Complex不存在了")
x = Complex(3.0,-4.5)
print(x.r, x.i)
print(x)
del x
3.class Animal:
def eat(self):
print 'Eating...'
class Dog(Animal):
def bark(self):
print 'Barking...'
d=Dog()
d.eat()
d.bark()
4.class Animal:
def run(self):
print ('调用父类方法')
class Cat (Animal):
def run (self):
print ('调用子类方法')
class Dog (Animal):
def run (self):
print ('调用子类方法')
c = Dog()
c. run ()
5.import os
fp=open(‘myData.dat', 'w+b')
fp.seek(0)
fp.write(b'Hello')
fp.write(b'World')
fp.seek(-5, os.SEEK_END)
line = fp.read(5)
print(line)
fp.tell( )