목록Python (14)
개발부터 자유까지
목차 Python String format 3가지 방식 % 포맷팅 format 함수 f-string 포맷팅 속도 비교 Python String Format 3가지 방식 % 포맷팅 % 문자를 사용해서 문자를 포맷팅한다. C언어에서 사용하는 printf 방식과 비슷하다. 파이썬에서는 권장하고 있지 않은 방식이다. 실수할 수 있는 부분이 많고 입력 자료형에 따라서 % 문자 뒤에 붙는 지시자가 다르다. i = float(input()) print("%f" $ i) # 입력: 12 # 출력: 12.000000 s = input() print("%s" % s) # 입력: water # 출력: water s = input() print("%f" % s) # 입력: 55 # 출력: Traceback (most rece..
black formatter 사용하기 1. vscode extension 에 "black formatter" 라고 검색하면 아래와 같은 확장자가 나옵니다. 2. ctrl + , (컨트롤+콤마)로 설정 창을 엽니다. Editor: Default Formatter에서 Black Formatter 로 변경합니다. 3. 설정 검색창에 format on save 를 다시 검색해서 Editor: Format On Save에 체크박스를 설정합니다. 4. 마지막으로 .py파일을 작성하고 저장시 formatting이 자동으로 되는것을 확인하실 수 있습니다.
예전에는 Anaconda 패키지를 잘 썼었는데 Anaconda가 유료로 전환되면서 파이썬이나 R 패키지를 사용하여 프로젝트를 진행하려고 할 때, miniforge를 사용할 수 있다. Anaconda 패키지를 경량화한 버전이고, 무료기 때문에 사용성이 좋다. 명령어는 Anaconda 를 사용하던 그대로 사용하면 된다. 1. miniforge 다운로드 아래 깃헙주소로 들어간다. https://github.com/conda-forge/miniforge GitHub - conda-forge/miniforge: A conda-forge distribution. A conda-forge distribution. Contribute to conda-forge/miniforge development by creatin..
python 명령어를 입력하면 2.7.18 버전으로 진입한다. alias 명령어를 사용해서 python 명령어를 python3 버전으로 변경할 수 있다. 하지만 bash 입력창을 나갔다가 다시 돌아오면 명령어는 원래대로 초기화되므로 다음과 같이 파일에 저장하여 바꿔준다. 1. .bashrc 파일을 수정 모드로 들어간다. 2. alias python=python3 명령어를 입력해준다. 3. python --version 명령어로 python 명령어가 3버전인지 확인한다.
pipenv 를 사용하는 이유 로컬에 설치되어 있는 파이썬 환경과 별도로 사용할 수 있는 가상 환경 제공 가상환경만을 위한 파이썬, 각종 library 설치하여 다른 프로젝트에 영향 방지 pipenv 설치 pip install pipenv PS C:\> pip install pipenv Collecting pipenv Downloading pipenv-2023.11.15-py3-none-any.whl (3.2 MB) ---------------------------------------- 3.2/3.2 MB 25.6 MB/s eta 0:00:00 Collecting setuptools>=67 Downloading setuptools-69.0.3-py3-none-any.whl (819 kB) -------..
str.isdigit() Return True if all characters in the string are digits and there is at least one character, False otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value..