본문 바로가기
Programming/Coding

python list test

by 강릉바다의 블로그 2023. 12. 18.
str = ["a","b","c"]
print(str)
print(str[1:])

str.append(["d","e"])
print(str)
print(str[3])

str[3]="d"
print(str)

del str[3]
print(str)

str.remove("c")
print(str)

del str[str.index("b")]
print(str)

str.insert(1,"b")
print(str)

str+=["c", "d"]
print(str)

cnt = 0
while cnt < len(str):
    print(str[cnt], end=" ")
    cnt += 1
print()

cnt = 0
while cnt < len(str):
    print(str[(cnt + 1) * (-1)], end=" ")
    cnt += 1
print()

str.sort(reverse = True)

for listItem in str:
    print(listItem, end=" ")

 

결과가 어떻게 출력될지 생각해보세요.

 

더보기
['a', 'b', 'c']
['b', 'c']
['a', 'b', 'c', ['d', 'e']]
['d', 'e']
['a', 'b', 'c', 'd']
['a', 'b', 'c']
['a', 'b']
['a']
['a', 'b']
['a', 'b', 'c', 'd']
a b c d 
d c b a 
d c b a