2016-07-02 4 views
-1

name, hoursqpoints과 같은 속성을 가진 Student 개체가 포함 된 목록이 있습니다. 목록은 변수 data에 저장됩니다. 다음에서 None 반품을받는 이유는 무엇입니까? 즉 은 Student 클래스의 gpa를 반환하는 메서드가 있지만 None을 반환합니다. 내 코드에 Student 클래스를 가져 왔습니다.목록의 목록을 파이썬 객체 목록

def choiceInput(data): 
    choice = input('Enter method of sorting <GPA>, <Name>, or <Credits>: ') 
    choice = choice[0].lower() 
    if choice == 'g': 
     return data.sort(key = Student.gpa) 
    elif choice == 'n': 
     return data.sort(key = Student.getName) 
    else: 
     return data.sort(key = Student.getpPoints) 
+0

이 위협 요소는 어디에서 찾을 수 있습니까? – lhoernle

답변

1

sort는 현재 위치에서 목록을 정렬하고 None를 반환합니다. sort을 호출 한 후 data을 인쇄하면 예상대로 정렬됩니다.

관련 문제