文件操作,面对对象

文件的打开与关闭
打开f = open('text.txt','w')
关闭close.()
文件的读写
写入f = open('test.txt','w')
f.write('hello world')
读取f = open('test.txt', 'r')
面对对象
类和对象的关系
类是对象的模子
对象是类的具体实例
定义类:
class 类名
class Car:
def getCarInfo(self):
print('车轮子个数:%d, 颜色%s'%(self.wheelNum, self.color))
def move(self):
print("车正在移动...")
创建对象格式
对象名 = 类名()

你可能感兴趣的:(文件操作,面对对象)