✏️파이썬을 배워보자 / 리스트list

1000명진·2023년 1월 16일
0
post-thumbnail

리스트 사용

hello = []

hello.append(1)
hello.append(2)
hello.append(4)
hello.append(7)

print(hello)
#결과값 => [1,2,4,7]

비어있는 hello 라는 리스트를 만들고
1,2,4,7 이라는 숫자를 하나씩 append(첨부)한다

리스트끼리 연산가능

days = ['월','화','수','목','금']
days2= ['토','일']

days+=days2
print(days)
#결과값 =>['월','화','수','목','금','토','일']

index값으로 요소출력하기

days = ['월','화','수','목','금']

print(days[3])
# 목 출력
print(days[-1])
# -1은 제일마지막요소를 출력한다
l = len(days)
print(days[l-1])
#len은 요소의 개수를알려준다
#전체요소개수 -1을하면 마지막요소가 출력된다
profile
심심할때쓰는 기록장

0개의 댓글