728x90
반응형

개요

  • 리스트는 배열이라고 생각하면 됨
  • 순서가 있는 자료의 집합

 

List add

  • append( )
  • insert( )
  • extend( )
# list add
type_list = []

type_list.append('물')
print(type_list)
#['물']


type_list = type_list + ['불', '풀']
print(type_list)
#['물', '불', '풀']


type_list.insert(0, "전기")
print(type_list)
#['전기', '물', '불', '풀']


type_list.insert(2, "에스퍼")
print(type_list)
#['전기', '물', '에스퍼', '불', '풀']


new_list=['독', '바람']
type_list.extend(new_list)
print(type_list)
#['전기', '물', '에스퍼', '불', '풀', '독', '바람']

 

 

 

List remove

  • remove( )
  • pop( )
  • del
  • clear( )
type_list = ['전기', '물', '불', '에스퍼', '독', '바람']

type_list.remove('독')
print(type_list)
#['전기', '물', '불', '에스퍼', '바람']


print(type_list.pop(3)) #에스퍼
print(type_list)
#['전기', '물', '불', '바람']


print(type_list.pop()) #바람
print(type_list)
#['전기', '물', '불']


del type_list[0] #전기
print(type_list)
#['물', '불']


type_list.clear()
print(type_list)
#[]

 

 

 

List print

#list print
type_list = ['전기', '물', '불', '바람', '악', '풀', '에스퍼']

print(type_list * 2)
#['전기', '물', '불', '바람', '악', '풀', '에스퍼', '전기', '물', '불', '바람', '악', '풀', '에스퍼']


print(type_list [2:5])
#['불', '바람', '악']


print(type_list [1:])
#['물', '불', '바람', '악', '풀', '에스퍼']


print(type_list [:2])
#['전기', '물']


print(type_list [-2])
# 풀
728x90

'*Programming > [ Py ] Python' 카테고리의 다른 글

[Py - N05] Set (중복제거)  (0) 2022.08.28
[Py - N04] Tuple  (0) 2022.08.28
[Py - N02] Format String  (0) 2022.08.28
[Py - N01] print( ) 과 input( )  (0) 2022.08.28
[Py - N00] Again Python  (0) 2022.08.28

+ Recent posts