반응형

전체 글 219

[Python] 딕셔너리

1. 딕셔너리 생성- dict() or {}- dicr() 로 중첩된 리스트로 딕셔너리 생성 가능empty = {}dict1 = { "one": "하나", "two": "둘" }dist2 = dict([["one", "하나"],["two", "둘"]])2. 값 참조- [] or getdict1 = { "one": "하나", "two": "둘" }val = dict1["one"] # 하나, 키가 없으면 keyErrorval = dict1.get("two") # 둘, 키가 없으면 noneval = dict1.get("three", "삼") # 삼3. 모든 키/값 가져오기dict1 = { "one": "하나", "two": "둘" }key = dict1.keys() # one, twoval = dict1.va..

IT/Python 2026.09.22

[Python] set 사용하기

1. set 사용하기- 순서 없음- 중복 없음- set() or {}s1 = {1,2,3}s2 = set([1,2,3,1,2]) # {1,2,3}empty = set()2. 요소 추가하기- adds1 = {1,2,3}s1.add(4) print(s1) # {1,2,3,4}s1.add(3)print(s1) # {1,2,3,4}3. 요소 삭제하기- remove- clears1 = {1,2,3}s1.remove(1)print(s1) # {2,3}s1.clear()print(s1) # {}4. 요소 확인하기- 값 in set_변수명s1 = {1,2,3}print(3 in s1) # Trueprint(4 in s1) # False5. 논리 연산- 합집합, 교집합, 차집합, 포함여부판정- union- interse..

IT/Python 2026.09.21

[Python] 언패킹, 변수값 치환, range 타입

1. 언패킹- 시퀀스 변수를 풀어서 변수에 담는다.- 좌변과 우변의 요소 수는 같아야 한다.list1 = [1,2,3]a, b, c = list1print(a,b,c) # 1,2,3a, b = list1 # validError: too many valuea, b, c, d = list1 # validError: not enough value2. 변수값 치환- 언패킹 형태로 변수값을 치환한다.a = 100b = 200a, b = b, a # a에 b를, b에 a가 대입print(a,b) # 200, 1003. range 타입- 특정한 범위의 연속된 숫자의 시퀀스를 가진다.r1 = range(stop) # 0 부터 stop - 1 까지r2 = range(start, stop) # start 부터 stop -..

IT/Python 2026.09.21

[Python] 튜플 사용하기

1. 튜플 생성- () 또는 tuple()- 한번 생성하면, 값과 순서를 변경할 수 없는 이뮤터블 변수이다.- 시퀀스 변수t1 = ()t2 = (1,) # 단일값일 경우 뒤에 콤마(,) 필수t3 = (1,2,3)t4 = 1,2,3 # 소괄호(())없이 콤마(,)로 생성 가능list1 = [1,2,3]t5 = tuple(list1) # (1,2,3)2. 튜플 요소와 길이- 인덱스 접근 참조- 슬라이스 구문 사용- len() 으로 길이 확인t1 = (1,2,3,4,5)print(t[1]) # 2print(t(1, 3)) # 2, 3print(len(t)) # 5

IT/Python 2026.09.17

[Python] 리스트 다루기

1. 생성- [] or list() 사용list1 = ['가', '나', '다']list2 = list('sample') # [s,a,m,p,l,e]empty1 = []empty2 = list()2. 요소 접근- 인덱스(첨자) 접근- 마지막 요소 접근 : 인덱스 -1list1 = ['가', '나', '다']print(list1[0]) # 가print(list1[1]) # 나print(list1[2]) # 다# 인덱스 -1print(list1[-1]) # 다print(list1[-2]) # 나print(list1[-3]) # 가4. 슬라이스 구문 사용법- 구문- 종료위치는 (종료위치 -1) 의 인덱스 요소까지의 값 list[시작위치 : 종료위치 : 간격]- 예시list1 = [0, 1, 2, 3, 4]# ..

IT/Python 2026.09.16

[Python] 문자열 다루기

- 문자열 생성 방법text1 = 'hello'text2 = "world"text3 = """hellopython"""text4 = str(3)- 문자열 이스케이프 처리- 역슬래쉬(\) 문자 사용\ # 줄바꿈 무시\' # 작은 따옴표\" # 쌍따옴표\n # 개행, 줄바꿈\r # 캐비지 리턴, 반환 \t # 탭- 문자열 합치기text1 = "hello"text2 = "world"num = 3result1 = text1 + text2 # helloworldresult2 = text2 + str(num) # world3- raw 문자열text1 = r"hello\tworld" # hello\tworldtext2 = "c:\\test" # c:\testtext3 = r"c:\test" # c:\test- 문자..

IT/Python 2026.09.11

[Linux] grep 명령어 정리

- 기본 구조grep [옵션] [찾을 문자열] [파일 이름]- 옵션 정리- 대소문자 구분 무시grep -i "error" *.log- 문자열 제외grep -v "error" *.log- 매칭된 라인의 총 건수grep -c "error" *.log- 바이너리 파일을 텍스트 파일처럼 취급grep -a "error" *.log- 확장 정규표현식(ERE)grep -E "error|warn" *.log- 매칭된 라인 이후(아래)grep -A 5 "error" *.log- 매칭된 라인 이전(위)grep -B 5 "error" *.log- 매칭된 라인 전후(위아래)grep -C 5 "error" *.log

IT/WSL 2026.09.11
반응형