定义类 people
包含2个变量,1个函数
class people:
idno = "";
name = "";
# def __init__(自引用参数名,idno,name):
#声明init函数后,必会被调用。如果想要无参调用,就需要给init设置参数默认值
def __init__(this,idno,name):
this.idno = idno;
this.name = name;
def describe(this):
print("------parent")
print(this.idno)
print(this.name)
定义一个对象数组,并进行赋值。
使用for访问数组,再用for 访问对象转字典后的item(),直接取 key 和 value
ps = [people("13000" + str(i) ,"tom" + str(i) ) for i in range(10)]
ct = -1
for x in ps:#遍历数组内 对象
ct+=1
print(str(ct) + "=======current people=======")
for k,n in x.__dict__.items():
print(k + "=" + n)
print("===========next people=============")