2014-02-12 3 views
0
attributes = [["strength", 0], ["health", 0], ["wisdom", 0], ["dexterity", 0]] 
attrib = raw_input("Which attribute would you like to add these points to? ") 
int(attrib) 
print attributes[attrib][1] 

출력 :초심자 파이썬 목록 오류 : "목록 색인은 정수가 아니고 str이 아니어야합니다"?

List indices must be integers, not str 

나는 ATTRIB는 사용자가 입력 한 숫자가되고 싶어요. 왜 내가이 오류를 얻는 지 모르겠다. 3 행의 정수로 문자열을 변환 한 것 같다.

이런 식으로 중첩 목록에 액세스 할 수 없다고 생각 하는가? 잃어버린 ...

답변

4

int(attrib)attrib에있는 내용을 정수로 "수정하지"않습니다. it 정수를 반환합니다. 원하는 내용은 다음과 같습니다.

attrib = int(attrib) 
관련 문제