RUBY
리스트 append() 함수(파이썬) 본문
append() 함수
append() 함수를 이용하면 마지막 인덱스에 아이템을 추가할 수 있다.
students = ['홍길동', '박찬호', '이용규', '박승철', '김지은']
students.append('강호동')
print('students : {}'.format(students))
print('students의 길이 : {}'.format(len(students)))
print('students의 마지막 인덱스 : {}'.format(len(students) -1))
students : ['홍길동', '박찬호', '이용규', '박승철', '김지은', '강호동']
students의 길이 : 6
students의 마지막 인덱스 : 5
scores = [['국어', 88], ['영어', 91]]
scores.append(['수학', 96])
print('scores : {}'.format(scores))
for subject, score in scores:
print('과목: {} \t 점수: {}'.format(subject, score))
scores : [['국어', 88], ['영어', 91], ['수학', 96]]
과목: 국어 점수: 88
과목: 영어 점수: 91
과목: 수학 점수: 96
'프로그래밍 언어 > Python' 카테고리의 다른 글
리스트 pop() 함수(파이썬) (0) | 2023.01.22 |
---|---|
리스트 insert() 함수(파이썬) (0) | 2023.01.22 |
리스트 enumerate()함수(파이썬) (1) | 2023.01.22 |
리스트와 while문(파이썬) (0) | 2023.01.22 |
리스트와 for문(파이썬) (0) | 2023.01.22 |
Comments