개발자료/Python(18)
-
String - 문자열
# Trim : 앞뒤 공백 제거 str = " String " str.lstrip() # 왼쪽 공백 제거 "String " str.rstrip() # 오른쪽 공백 제거 " String" str.strip() # 양쪽 공백 제거 "String" # starswith : 문자열 시작 비교 str = "start center end" if str.startswith("start"): print("has start") # endswith : 문자열 끝 비교 str = "start center end" if str.endswith("end"): print("has end")
2020.09.18 -
Dictionary - 딕셔너리
# 생성 dic = {} dic = {'key1':'value1', 'key2':'value2'} # 추가 dic['key3'] = 'value3' # 수정 dic['key3'] = 'value3-1' # 삭제 del dic['key3'] # 키 구하기 dic.keys() # 리스트 변환 list(dic.keys()) # 값 구하기 dic.values() # 리스트 변환 list(dic.values())
2020.04.02 -
PIP - 모듈 설치 명령어
# pip install {module name}
2020.03.16 -
[module] datetime
# import import datetime # 연월일시분초.마이크로초 print(datetime.datetime.now()) 2020-02-01 17:45:24.474160 # 시분초.마이크로초 print(datetime.datetime.now().time()) 17:45:25.474160 # datetime 사용간소화 from datetime import datetime 이후에는 datetime.now() 형태로 사용하면 된다. 참고사이트 https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior 8.1. datetime — Basic date and time types — Python 2.7.17 documentation 8..
2020.02.01 -
배열, Array, 리스트, List
# 생성 arr = [] arr = list() arr = [1, 2, 3, 4, 5] arr = [1, 2, 'a', 'b', 'c'] arr = [1, 2, ['a', 'b']] # 삭제 del arr[1] # 요소 삭제 del arr[2:] # 슬라이싱 기법 삭제 del arr # 객체 삭제 # 추가 arr.append(6) arr.append([6, 7]) # 개수(길이) 확인 len(arr)
2020.01.29 -
URL 파싱
from urllib.parse import urlparse parts = urlparse("https://domain.com/page.php?key1=value1&key2=value2#fragment") print(parts) -- print -- ParseResult(scheme='https', netloc='domain.com', path='page.php', params='', query='key1=value1&key2=value2', fragment='fragment')
2020.01.24