面向对象
对象是类的实例
定义类
class class_name(object):
print('hello')
if __name__ =="__main__":
joker = class_name
真正的类需要重写init函数
class class_name(object):
def __init__(self):
print('hello')
if __name__=="__main__":
joker = class_name()
()相当于初始化init
class class_name(object):
def __init__(self):
self.a=100
def A(self):
print(self.a)
if __name__=="__main__":
joker = class_name()
joker.A()
在类中调用函数:类名.函数名(例joker.A())
进度条练习
import time
class xx(object):
def __init__(self):
self.count = 1
def jindutiao(self):
for i in range(0,100):
time.sleep(0.1)
print('%d%%\r'%(i+1),end="",flush=True)
if i%5 ==0: