1-D arrays (lists) · 1-D 배열 (리스트)
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
A list holds many values
- A list (the exam calls it an array) stores many values under one name.
- Write the items in square brackets, separated by commas.
- An array normally stores items of the same type.
한국어
목록은 여러 값을 담습니다
- 목록(시험에서는 배열이라고 부름)은 하나의 이름 아래에 여러 값을 저장합니다.
- 항목들을 대괄호 안에 적고 썸표로 구분하여 나열합니다.
- 배열은 일반적으로 동일한 형식의 항목을 저장합니다.
scores = [40, 55, 72, 90]
print(scores)
English
Reach an item by its index
- Each item has a position number called its index.
- Python counts from 0, so the first item is
scores[0].
한국어
인덱스로 항목에 접근하기
- 각 항목에는 위치 번호인 인덱스가 있습니다.
- Python은 0부터 세므로 첫 번째 항목은
scores[0]입니다.
scores = [40, 55, 72, 90]
print(scores[0]) # 40
print(scores[2]) # 72
Explore · 탐색하기
Index and change a list · 리스트 인덱스 및 변경
Items are numbered from 0; scores[0] is the first item. · 항목 번호는 0부터 시작하므로, scores[0]은 첫 번째 항목입니다.
English
Change an item
- Assign to an index to replace that one item.
한국어
항목 변경하기
- 특정 인덱스에 할당하여 해당 항목을 교체할 수 있습니다.
scores = [40, 55, 72, 90]
scores[1] = 99
print(scores) # [40, 99, 72, 90]
English
Length and looping
len(scores)gives how many items there are.- A
forloop visits each item in turn.
한국어
길이와 루프
len(scores)는 항목의 총 개수를 알려줍니다.for루프는 순서대로 각 항목을 방문합니다.
scores = [40, 55, 72, 90]
print(len(scores)) # 4
for s in scores:
print(s)
English
In the exam: arrays start at 1
- Pseudocode declares an array with a size, and usually counts from 1.
한국어
시험: 배열은 1에서 시작합니다
- 가짜코드(가상코드)는 크기를 가진 배열을 선언하며, 일반적으로 1부터 카운트합니다.
DECLARE Scores : ARRAY[1:4] OF INTEGER
Scores[1] ← 40
OUTPUT Scores[1]
English
Common mistakes
- Index from
0; the last item is at positionlength - 1. - Going past the end gives an index error.
한국어
흔한 실수
- 인덱스는
0부터 시작하며; 마지막 항목은 위치length - 1에 있습니다. - 끝을 넘어가는 것은 인덱스 오류를 발생시킵니다.
English
Now you try
- Use an index, or a loop, on each list.
- Press Check answer to test your code.
한국어
이제 직접 해보기
- 각 리스트에 대해 인덱스나 루프를 사용하십시오.
- Answer 확인 버튼을 눌러 코드를 테스트하세요.
The list colours is set for you. Store its second item in a variable called second (remember Python counts from 0). · 리스트 colours이 미리 설정되어 있습니다. 이 리스트의 두 번째 항목을 변수 second에 저장하세요 (Python은 0부터 세는 것을 기억하세요).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Change the first item of the list nums to 99. · 리스트 nums의 첫 번째 항목을 99로 변경하세요.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Use a loop to add up every number in nums and store the result in total (the answer is 43). · 루프를 사용하여 리스트 nums의 모든 숫자의 합을 구하고 결과를 변수 total에 저장하세요 (정답은 43).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.