Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

RUBY

리스트 append() 함수(파이썬) 본문

프로그래밍 언어/Python

리스트 append() 함수(파이썬)

ruby-jieun 2023. 1. 22. 21:59

 

 

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

 

 

Comments