美文网首页
文件操作,面对对象

文件操作,面对对象

作者: 冥千洛 | 来源:发表于2018-07-15 19:46 被阅读0次

    文件的打开与关闭
    打开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("车正在移动...")
    创建对象格式
    对象名 = 类名()

    相关文章

      网友评论

          本文标题:文件操作,面对对象

          本文链接:https://www.haomeiwen.com/subject/umzppftx.html