-
day01Python/개념학습 2022. 7. 25. 12:301print(d[-1][0]) # 출력값 : Myungseo
cs 2. 인덱스 지정해 값 변경
12345# List 연속된 값으로 변경test = [1, 2, 3, 4, 5]test[2:3] = ['a', 'b', 'c']print(test) # [1, 2, 'a', 'b', 'c', '4', '5']3.인덱스 요소 삭제
1234567891011# 리스트 요소 삭제 방법test = ['a', 'b', 'c', 'd', 'e']# 1.test[2:4]=[] # test = ['a', 'b', 'e']#2.del test [2:4] # test = ['a', 'b', 'e']#3.del test [2] # test = ['a', 'b', 'd', 'e']cs 123test = [1, 2, 3, 4, 3]test.remove(3)print(test) #test = [1, 2, 4, 3]cs 4. reverse, delete
123456789101112131415test = [3, 1, 2, 5, 4]test.sort(reverse = True)print(test) #[5, 4, 3, 2, 1]test.reverse()print(test) #[4, 5, 2, 1, 3]#list의 인덱스값 출력print(test.index(0)) # [3]cs 5. list내장함수 활용
12345678test_list = [1, 2, 3, 4, 5]result = []for num in test_list:result.append(num*3)print(result) # [3, 6, 9, 12, 15]cs =
12345test_list = [1, 2, 3, 4, 5]result = [num * 3 for in test_list]print(result) # [3, 6, 9, 12, 15]cs 'Python > 개념학습' 카테고리의 다른 글
Meaning of stack[-1][0] (0) 2022.08.24 collections 모듈 - extend, append (0) 2022.08.21 Day05 더 빠르게 입력받기 : sys.stdin.readline() (0) 2022.08.13 Day04 아스키코드<->문자열 변환 함수 : ord - chr (0) 2022.08.10 Day03 (0) 2022.07.30