-
Python : ListProgramming/Python 2023. 9. 19. 16:47
파이썬의 자료구조
리스트
[ ]
리스트의 인덱싱과 슬라이싱
squares = [1,4,9,16,25]
squares[-1] : 마지막 요소
squares[0,4] : 0부터 4-1까지리스트 합치기
리스트a + 리스트b
연산자 오버로딩
데이터형식이에 따라서 결과값이 다름
일반 숫자에서 +와 리스트의 +가 다른 것처럼
operate overloading중첩리스트
2차원 리스트
2차원리스트 list2d[0]
list2d[0]은 첫번째줄객체
객체 : 2가지 형태의 속성으로 ( 속성: 값 , 메소드: 객체에 소속된 함수 )로 구성
메소드 ex : 내장함수, sum, min, max 등sort 는 원래 리스트 그대로, 정렬된 새로운 리스트를 만들어줌
DEFAULT : 오름차순
reverse=True : 역순 배열c언어의 배열과 비슷한 파이썬의 리스트
동일한 타입이 아니어도 가능한 파이썬의 리스트
2차원 3차원 등의 다차원 리스트 만들 수 있음numpy - array : 처리속도가 빠름, 효율적
튜플
리스트와 비슷하나 요소 값을 변경할 수 없다. 학생의 신상정보 등, 한번에 모든 것을 모아서
요소 element, 집합 set
( )리스트와 튜플, 상호 변환이 가능하다.
튜플 언패킹
a,b,c = (1,2,3) 하나씩 연결해 저장
튜플의 요소를 하나씩 변수에 할당, 언패킹딕셔너리 dictionary
키key : 값 value 로 구성되는 자료 구조
키는 정수, 실수, 문자열, 튜플
값은 임의의 데이터형test = dict() : 빈 딕셔너리 생성, a={ }
딕셔너리 키 조사
'Kim' in height
딕셔너리의 키, 값, 요소를 뽑아내기
.claer()은 요소 지우기, 빈 딕셔너리로 만든다.
집합 set
: 집합은 많이 사용하지 않는 것 같음 ( 넘어가심 )
함수 function
: 이름을 붙여 반복적으로 사용할 수 있는 프로그램 부분
특정형태의 기능 수행특정 함수가 기능을 온전하게 수행 잘 할 때
함수는 변수로 할당 : 함수를 변수처럼 사용 : 파이썬에서
재사용성 높이기 위해 객체지향 프로그래밍
사용자 정의 함수
def 함수이름(매개변수) : 함수의 이름과 매개변수 정의
return 값 : 반환 값, 들여쓰기가 끝나는 부분까지 함수파라미터 : 함수에 추가적인 정보
'Programming > Python' 카테고리의 다른 글
Socket ? (0) 2023.10.12 0921 파이썬 노트 필기 (0) 2023.09.21 파이썬 0907/ 0912 (0) 2023.09.12 코딩애플 : 빠르게 정리하는 파이썬 기초 문법 (0) 2022.11.21 1분 파이썬 (0) 2022.11.21