건설.
목록 이름 = (요소1, 요소2, 요소3)
전화: 목록 이름(0)
전)
nums = (1, 2, 3, 4, 5, 6)
!!!! 이모티콘 사용시 단말기가 튕겨서 단말기에 보이지 않는 것 같습니다.
훈련
list1 = ("a","b","c","d")
print(list1)
print(type(list1))
print(list1(1))
#('a', 'b', 'c', 'd')
#<class 'list'>
#b
목록 슬라이싱
슬라이스는 공유를 의미합니다
list1 = ("a","b","c","d")
print(list1(2:))
#('c', 'd')
목록 추가
+ 기호를 사용하여 목록에 가입하세요.
list2 = (1, 2, 3)
list3 = (4, 5, 6)
list4 = list2 + list3
print(list4)
#(1, 2, 3, 4, 5, 6)
목록을 반복
* 기호는 목록을 반복하고 새 목록을 반환합니다.
list2 = (1, 2, 3)
list5 = list2 * 3
print(list5)
#(1, 2, 3, 1, 2, 3, 1, 2, 3)
리스트의 길이 찾기 len(list)
위의 list5 다음
print(len(list5))
#9
목록 수정, 삭제(delete object)
모든 데이터 유형을 삭제할 수 있습니다.
list2 = (1, 2, 3)
list5 = (1, 2, 3, 1, 2, 3, 1, 2, 3)
list2(0) = 10
print(list2) #(10, 2, 3)
del list2(0)
del list5(4:)
print(list5) #(1, 2, 3, 1)
print(list2) #(2, 3)
목록 관련 기능
1. 추가()
목록에 마지막 항목 추가
건설)
list.append(추가할 항목)
students = ("stu1","stu2","stu3","stu4")
students.append("stu5")
print(students)
#('stu1', 'stu2', 'stu3', 'stu4', 'stu5')
2.insert(시작, 값)
목록에 항목 삽입 시작 위치(원하는 위치)에 값을 삽입합니다.
건설)
목록.삽입(2,20)
students = ("stu1","stu2","stu3","stu4")
students.insert(1,"newStu")
print(students)
#('stu1', 'newStu', 'stu2', 'stu3', 'stu4', 'stu5')
3. 반전()
플립 목록
건설)
list.reverse()
students = ("stu1","stu2","stu3","stu4")
students.reverse()
print(students)
#('stu5', 'stu4', 'stu3', 'stu2', 'newStu', 'stu1')
4.정렬()
목록의 항목을 순서대로 정렬
건설)
list.sort()
students.sort()
print(students)
#('newStu', 'stu1', 'stu2', 'stu3', 'stu4', 'stu5')
numberList = (5,2,1,6,7,8,2,10)
numberList.sort()
print(numberList)
#(1, 2, 2, 5, 6, 7, 8, 10)
5.인덱스()
값이 목록에 있으면 해당 값의 인덱스 값이 반환됩니다. 그렇지 않으면 오류가 발생합니다!!!!
건설)
list.index(값)
students = ("stu1","stu2","stu3","stu4")
num = students.index("stu3")
print(num)
#3
6. 제거(가치)
목록에서 첫 번째 값 삭제(중복 값이 있어도 하나만 삭제)
건설)
목록.제거(값)
students = ("stu1","stu2","stu3","stu4")
students.remove("stu3")
print(students)
#('newStu', 'stu1', 'stu2', 'stu4', 'stu5')
numberList.remove(2)
print(numberList)
#(1, 2, 5, 6, 7, 8, 10)
7.팝()
목록의 마지막 요소를 반환하고 이 요소를 삭제합니다.
건설)
목록.팝()
students = ("stu1","stu2","stu3","stu4")
lastList = students.pop()
print(lastList)
print(students)
#stu5
#('newStu', 'stu1', 'stu2', 'stu4')
8.카운트(값)
목록의 값 수를 반환합니다.
건설)
list.count(3)
fruits = ("사과", "딸기", "사과", "바나나", "사과", "귤")
applenum = fruits.count('사과')
print(applenum)
#3
![[Dart] 알고 있으면 좋은 [Dart] 알고 있으면 좋은](https://blog.notus.kr/wp-content/plugins/contextual-related-posts/default.png)