Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- asynchronization
- barplot
- 버스분석
- R데이터형태
- 백준 10172
- React
- 값삭제
- 값추가
- R 그래프
- 광명시버스분석
- 10172
- await
- barplot in r
- 배열추가
- 데이터분석
- 백준
- DataFrame
- vetor
- getline
- 이스케이프시퀀스
- useState
- plot in r
- 백준 11718
- setstate
- 그대로 출력하기
- react #회원가입 #비밀번호비교
- 배열삭제
- 이용현황분석
- 탈출문자
- 그래픽
Archives
- Today
- Total
devlog_zz
[ python ] list 복사 ( copy() ) 본문
728x90
list를 복사할 때
arr = arr2 이와 같이 할당하듯이 복사한다면
list는 1개만 존재하지만 2가지 이름으로 가리키게 되어 하나의 list의 삭제,추가와 같은 작업을하면 원본 list에도 동일하게 적용된다.
arr1 = [0,1,2,3,4,5]
print(arr1)
# [0, 1, 2, 3, 4, 5]
arr2 = arr1
arr2.remove(0)
print(arr1)
# [1, 2, 3, 4, 5]
print(arr2)
# [1, 2, 3, 4, 5]
b를 수정해도 a가 바뀌길 원치 않는다면 .copy() 사용하여 복사
arr1 = [0,1,2,3,4,5]
print(arr1)
# [0, 1, 2, 3, 4, 5]
arr2 = arr1
arr2.remove(0)
print(arr1)
# [0, 1, 2, 3, 4, 5]
print(arr2)
# [1, 2, 3, 4, 5]
728x90
'Back End > python' 카테고리의 다른 글
[ python ] list에서 for문으로 remove() 시 주의하기 - list[:] (0) | 2022.08.13 |
---|---|
[python] range() 함수 활용 - 감소하는 list 생성, 증가하는 list 생성 (0) | 2022.08.07 |
[python] list sort() , sorted() 차이 (0) | 2022.08.07 |
[python] list 일부 선택하기 arr[2:5] (0) | 2022.08.07 |
[python] list 최대값, 최소값 index (0) | 2022.08.07 |
Comments