본문 바로가기
반응형

Programming Language131

[Javascript/정규표현식] 텍스트에서 줄바꿈(엔터) 제거하기 구문 let str = str.replace(/\n/ig, ''); * "\n"은 엔터라는 뜻입니다. * "g"는 전체 문자열을 탐색해서 모든 일치를 반환하도록 지정하는 전역 탐색 플래그입니다. 2023. 2. 20.
[Python] datetime.timedelta 클래스 기초 구문 class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) 설명 (1) timedelta란? 두 날짜나 시간 또는 datetime 인스턴스간의 차이를, 마이크로초 해상도로 출력하는 객체입니다. timedelta 인자들의 기본값은 0이며, 정수나 부동 소수점, 양수나 음수가 될 수 있습니다. 필요한 모든 인자들을 timedelta 객체에 넣으면 days, seconds, microseconds만 내부적으로 저장됩니다. 다음의 예시 처럼요. from datetime import timedelta delta = timedelta( days=50, seconds=27, micro.. 2023. 2. 10.
[Javascript] null과 undefined 처리 시, 널 병합 연산자 사용해보기 대표 예시 const foo = null ?? 'default string'; console.log(foo); // 출력 결과 --> "default string" const baz = 0 ?? 42; console.log(baz); // 출력 결과 --> 0 설명 널 병합 연산자( ?? ) 는 왼쪽 표현식이 null, undefined일 때 오른쪽 표현식 결과를 반환합니다. 보통 null, undefined 처리 시 논리연산자 OR( || )를 사용하는데요, 논리연산자 OR은 falsy한 값, 즉 0, '', NaN도 유효하지 않은 값으로 처리합니다. null과 undefined일 때만 오른쪽 표현식 결과를 반환하고 싶다면 널 병합 연산자( ?? ) 를 사용해 보세요. 널 병합 연산자와 논리 연산자 O.. 2023. 2. 9.
[Python] 파일/폴더 경로 존재 유무 확인하는 함수 [Python] 파일/폴더 경로 존재 유무 확인하는 함수 구문 os.path.exists(경로) 설명 이 함수는 경로가 존재하면 True, 존재하지 않으면 False를 반환합니다. 예시 import os.path if os.path.exists(r"C:\test1\test2.txt") : print("파일 존재") else : print("파일 없음") * python에서 string앞에 r을 붙여주면, string literal을 raw string으로 출력, 즉, 모든 Escape 문자를 그대로 출력해 줍니다. 참조 파이썬 도큐먼트 https://docs.python.org/3.11/library/os.path.html?highlight=path%20exists#os.path.exists os.pat.. 2023. 2. 9.
[Python] 파이썬 현재 경로(디렉토리) getcwd() 쓰세요. [Python] 파이썬 현재 경로(디렉토리) getcwd() 쓰세요. 구문 import os print( os.getcwd() ) 설명 getcwd()는 현재 디렉토리를 문자열로 반환하는 함수입니다. 참조 파이썬 도큐먼트 https://docs.python.org/3.11/library/os.html?highlight=getcwd#os.getcwd os — Miscellaneous operating system interfaces Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see .. 2023. 2. 9.
반응형