feat: add class person
This commit is contained in:
19
ClassPerson.py
Executable file
19
ClassPerson.py
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
class Person():
|
||||||
|
def __init__(self, name, age):
|
||||||
|
self.name = name
|
||||||
|
self.age = age
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return repr((self.name, self.age))
|
||||||
|
|
||||||
|
people = [
|
||||||
|
Person("tom", 22),
|
||||||
|
Person("jack", 11),
|
||||||
|
Person("jerry", 33)
|
||||||
|
]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sorted_people = sorted(people, key=lambda person: person.age)
|
||||||
|
print(sorted_people)
|
||||||
Reference in New Issue
Block a user