학습 목표

  • 리스트와 튜플의 기본 개념과 차이점을 이해한다.
  • 데이터를 리스트와 튜플로 저장하고 인덱싱, 슬라이싱 등 기본 조작을 수행할 수 있다.
  • 리스트 메서드(append(), remove() 등)를 사용할 수 있다.

리스트(list) 기초

6.1 리스트란?

  • 여러 개의 값을 하나의 변수에 담을 수 있는 자료형
  • 대괄호 [] 사용
fruits = ["사과", "바나나", "딸기"]

6.2 리스트 인덱싱 & 슬라이싱

print(fruits[0])     # 사과
print(fruits[1:3])   # ["바나나", "딸기"]
  • 인덱스는 0부터 시작
  • [:]로 일부 항목 가져오기

실습 1: 나의 리스트 만들기

문제: 좋아하는 음식 5가지를 리스트로 만들고 2번째, 마지막 항목을 출력해보세요.

모범답안:

foods = ["피자", "떡볶이", "초밥", "치킨", "김밥"]
print("두 번째 음식:", foods[1])
print("마지막 음식:", foods[-1])

해설:

  • [-1]은 마지막 요소를 의미합니다.

6.3 리스트 메서드 사용

  • append() → 끝에 항목 추가
  • remove() → 항목 삭제
  • len() → 길이 확인
animals = ["강아지", "고양이"]
animals.append("토끼")
animals.remove("고양이")
print(animals)
print("길이:", len(animals))

실습 2: 리스트 수정하기

문제:

  1. 리스트에 “사자” 추가
  2. “토끼” 삭제
  3. 전체 리스트와 항목 개수 출력

모범답안:

zoo = ["토끼", "호랑이", "곰"]
zoo.append("사자")
zoo.remove("토끼")
print(zoo)
print("동물 수:", len(zoo))

해설:

  • append()는 항상 마지막에 추가됩니다.
  • remove()는 처음 나타나는 항목 하나만 제거합니다.

6.4 리스트 반복 출력

colors = ["빨강", "파랑", "노랑"]
for color in colors:
    print("색상:", color)

실습 3: 리스트 항목 출력

문제: 좋아하는 영화 3개를 리스트에 저장하고 for문으로 출력하세요.

모범답안:

movies = ["어벤져스", "겨울왕국", "엘리멘탈"]
for movie in movies:
    print("영화:", movie)

해설:

  • 리스트는 for문과 잘 어울립니다.

튜플(tuple)과 리스트 vs 튜플 비교

6.5 튜플이란?

  • 리스트와 비슷하지만 값을 바꿀 수 없음(불변)
  • 소괄호 () 사용
point = (10, 20)
print(point[0])  # 10

6.6 튜플 특징 정리

구분 리스트(list) 튜플(tuple)
괄호 [] ()
변경 가능 가능 불가능
사용 용도 일반적 데이터 변경 필요 없는 좌표, 설정값 등

6.7 튜플 활용 예제

실습 4: 좌표 저장하기

문제: 점 3개를 튜플로 저장하고 각각 출력해보세요.

모범답안:

point1 = (1, 2)
point2 = (3, 4)
point3 = (5, 6)

print("점 1:", point1)
print("점 2:", point2)
print("점 3:", point3)

해설:

  • 튜플은 주로 변경하지 않을 데이터에 사용됩니다.

6.8 리스트와 튜플 종합 연습

실습 5: 학생 점수 관리 시스템 (리스트 + 튜플)

문제: 학생 이름 리스트와, 각 학생의 점수를 튜플로 저장하고 출력하세요.

모범답안:

students = ["지민", "서윤", "하준"]
scores = [(90, 95), (85, 87), (100, 98)]

for i in range(len(students)):
    print(students[i], "점수:", scores[i])

해설:

  • 리스트와 튜플을 함께 사용하면 구조화된 정보를 저장할 수 있습니다.
  • len()range()를 함께 사용해 인덱스로 접근합니다.

마무리 퀴즈 & 정리

  1. 리스트와 튜플의 가장 큰 차이점은? → 리스트는 변경 가능, 튜플은 불가능
  2. 리스트에 항목을 추가하는 함수는? → append()
  3. 튜플을 쓸 수 있는 예시는? → 좌표, RGB 색상값 등 고정 데이터

다음 시간 예고

딕셔너리와 집합을 배워서 키와 값을 연결하는 구조를 배우고, 중복 없는 집합도 함께 배워볼 거예요!


TechTinkerer's에서 더 알아보기

구독을 신청하면 최신 게시물을 이메일로 받아볼 수 있습니다.

댓글 남기기

  • The Fate of Greenland hangs in the Balance: A Global Power Play

    The fate of Greenland has become a focal point of global politics, with multiple nations vying for control over the strategic island. In recent weeks, several countries have expressed interest in acquiring or partnering with Greenland to further their interests. This article will examine the situation and explore the potential implications for international relations. The…

  • **South Korea’s Ambassador to the US Returns from Absence**

    After a year-long vacancy, South Korean Ambassador to the United States Kevin Kim has returned to his post. The ambassador’s return comes as a welcome relief for the South Korean government, which had been without an ambassador to the US since Kim’s departure in 2022. The cause of Kim’s absence was not publicly disclosed, but…

  • Building a Dynamic Landing Page: Mastering HTML, CSS, & JavaScript

    Welcome to My Website This is a basic landing page example. Click Me!

  • Mastering File Input/Output in C++

    [Tutorial] · 2026-01-15 08:44 UTC Mastering File Input/Output in C++ 💡 TL;DR Learn how to read from and write to files in C++ using the ifstream and ofstream objects, along with clear explanations of key concepts. 📚 Learning Objectives This tutorial explores file input/output operations in C++, covering essential concepts, practical examples, and best practices…

  • Mastering the Fundamentals of Object-Oriented Programming in C++

    [Tutorial] · 2026-01-15 04:15 UTC Mastering the Fundamentals of Object-Oriented Programming in C++ 💡 TL;DR Learn how to structure your code with classes, define objects, encapsulate data, and leverage inheritance for efficient development. 📚 Learning Objectives This tutorial introduces object-oriented programming concepts in C++, focusing on classes, objects, encapsulation, and inheritance. You’ll gain practical skills…

← 뒤로

응답해 주셔서 감사합니다. ✨

TechTinkerer's에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

계속 읽기

TechTinkerer's에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

계속 읽기