학습 목표

  • 리스트와 튜플의 기본 개념과 차이점을 이해한다.
  • 데이터를 리스트와 튜플로 저장하고 인덱싱, 슬라이싱 등 기본 조작을 수행할 수 있다.
  • 리스트 메서드(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에서 더 알아보기

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

댓글 남기기

  • Understanding Pointers and Memory Management in C++

    [Tutorial] · 2026-04-30 05:10 UTC Understanding Pointers and Memory Management in C++ 💡 TL;DR Mastering pointers in C++ is crucial for efficient memory management and writing effective code. 📚 Learning Objectives This tutorial covers the fundamentals of pointers in C++, including declaration, initialization, and memory management. Students will learn how to effectively use pointers to…

  • Building a Command-Line Calculator with C++

    [Tutorial] · 2026-04-30 04:08 UTC Building a Command-Line Calculator with C++ 💡 TL;DR Learn how to build a command-line calculator in C++ that takes user input and performs basic arithmetic operations. 📚 Learning Objectives This tutorial guides you through creating a basic command-line calculator in C++. You’ll learn how to take user input, perform arithmetic…

  • Mastering Python Data Structures for Efficient Coding

    [Tutorial] · 2026-04-30 03:05 UTC Mastering Python Data Structures for Efficient Coding 💡 TL;DR Learn about Python’s fundamental data structures – arrays, lists, tuples, and dictionaries – to write efficient and scalable code. 📚 Learning Objectives This tutorial covers the essential Python data structures – arrays, lists, tuples, and dictionaries. You’ll learn about their usage,…

  • Introduction to Object-Oriented Programming in Python

    [Tutorial] · 2026-04-30 02:02 UTC Introduction to Object-Oriented Programming in Python 💡 TL;DR Learn the fundamentals of object-oriented programming in Python, including classes and objects, inheritance, and polymorphism. 📚 Learning Objectives This tutorial introduces the basics of object-oriented programming in Python, covering classes, objects, inheritance, and polymorphism. By the end of this tutorial, beginners will…

  • Complete Guide to Python List Comprehensions

    [Tutorial] · 2026-04-30 01:00 UTC Complete Guide to Python List Comprehensions 💡 TL;DR Master Python list comprehensions to write concise and efficient code for data manipulation and transformation tasks. 📚 Learning Objectives This tutorial covers the basics of Python list comprehensions, including syntax, use cases, and execution results. You’ll learn how to write efficient and…

← 뒤로

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

TechTinkerer's에서 더 알아보기

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

계속 읽기

TechTinkerer's에서 더 알아보기

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

계속 읽기