这样写有什么不妥的地方吗?
class Person:
name=""
def __init__(self):
pass
def compare_name(Person_list,Person_c):
for i in range(0,len(Person_list)):
if i <= (len(Person_list)-2):
name_a = Person_list[i].name.lower()
name_b = Person_list[i+1].name.lower()
if name_a > name_b:
lowercompare=1
else:
lowercompare=0
name_a = Person_list[i].name.upper()
name_b = Person_list[i+1].name.upper()
if name_a > name_b:
uppercompare=1
else:
uppercompare=0
if lowercompare ==1 and uppercompare ==1:
Person_c = Person_list[i+1]
Person_list[i+1] = Person_list[i]
Person_list[i] = Person_c
return Person_list
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
p4=Person()
L1 = [p1, p2, p3]
L2 = compare_name(L1,p4)
print L2
print L2[0].name
print L2[1].name
print L2[2].name
还有为什么参考代码里面,类没有name变量,P1 P2 P3 初始化时可以去给那么赋值,这点有疑问