# 인덱싱 Indexing
# 인덱스를 이용하여 " 하나의 원소를 " 불러오는 것
# 기본 형태: 변수이름[인덱스]
word='알고학원'
print(word[0])
print(word[3])


# 슬라이싱 slicing
# 문자열이나 리스트의 일부분을 " 자르는 것 "
# 기본 형태: 변수 이름[시작인덱스(이상):종료인덱스(미만)]
# ★중요★   종료인덱스는 미만
numbers=[0,1,2,3,4,5,6,7,8,9]
print(numbers[1:3])
print(numbers[0:10])
print(numbers[3])         #시작인덱스 생략: 처음부터
print(numbers[6:])        #종료인덱스 생략: 끝까지
print(numbers[:])         #모든 인덱스 생략: 다



print('\n----- 문제 1 -----')
friends = ['윤우', '은우', '유민', '지수']

# 1. ['윤우', '은우'] 만 리스트에서 잘라내어 출력해보자
print(friends[0:2])
# 2. ['유민', '지수'] 만 리스트에서 잘라내어 출력해보자
print(friends[2:4])
# 3. ['은우', '유민'] 만 리스트에서 잘라내어 출력해보자
print(friends[1:3])

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: