Python list 생성, 접근, 반복문, 제거 등 (파이썬 리스트)
Python 코딩시에 list도 많이 사용하시죠??
가장 기본적인 문법에 대한 예시 몇개 소개하겠습니다.
항상 많이 사용하는 내용들이니... 같이 잘 숙지하시죠. ^^
1. Python list 생성 예시
thislist = ["apple", "banana", "cherry"]
print(thislist)
==> 결과 : ['apple', 'banana', 'cherry']
2. Python list item 접근
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
==> 결과 : banana
3. Pythoh list의 item 변경
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)
==> 결과 : ['apple', 'blackcurrant', 'cherry']
4. Python list 반복문
thislist = ["apple", "banana", "cherry"]
for x in thislist:
print(x)
==> 결과 :
apple
banana
cherry
5. Python list의 item 제거
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
==> 결과 : ['apple', 'cherry']
추가로 list 관련 정보는 아래 공식페이지를 참고해 주세요~~ ^^
https://www.w3schools.com/python/python_examples.asp