일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Front
- clean code
- 머신러닝
- cs
- Meta Learning
- CV
- 딥러닝
- 3d
- computervision
- PRML
- REACT
- algorithm
- Python
- dl
- pytorch
- ML
- Depth estimation
- math
- 자료구조
- GAN
- Vision
- classification
- FineGrained
- 알고리즘
- nlp
- web
- Torch
- SSL
- FGVC
- nerf
- Today
- Total
KalelPark's LAB
[ CLEAN CODE ] PEP(Python enhancement proposal) 8, string? 본문
[ CLEAN CODE ] PEP(Python enhancement proposal) 8, string?
kalelpark 2023. 3. 12. 09:57PEP(Python Enhancement Proposal) 8이란?
- Python 코드를 어떤 형식으로 작성할지 알려주는 가이드라인이다.
* 파이썬 커뮤니티에서 자주 활용되는 방안이기에, 참조하시기 바랍니다.
https://peps.python.org/pep-0008/
PEP 8 – Style Guide for Python Code | peps.python.org
PEP 8 – Style Guide for Python Code Author: Guido van Rossum , Barry Warsaw , Nick Coghlan Status: Active Type: Process Created: 05-Jul-2001 Post-History: 05-Jul-2001, 01-Aug-2013 Table of Contents This document gives coding conventions for the Python co
peps.python.org
자주 활용되는 핵심적인 것들만 톺아보자면..
공백
- 함수와 클래스 사이는 공백 2줄을 추가하기
- 메서드와 메서드사이에서 공백 1줄을 추가하기
- 딕셔너리의 key, value에서는 공백을 넣지 않기
명명 규약
- 함수, 변수, Attribute는 lowercase_underscore를 사용할 것 (snake case)
- 클래스 및 예외처리는 CapitalizeWord 사용하기 (Camel case)
임포트문 순서
- 반드시 알파벳순으로, 대체적으로 절대경로를 기준으로 하는 것이 좋습니다.
파이썬에서는 문자열을 출력하는 경우, C style보다는 내장함수 format과 str.format을 지향합니다. ( 고급 문자열 형식화 )
a = 1234.5678
formatted = format(a, ",.2f") // 천 단위 구분자를 표시할 때 사용
print(formatted)
b = "my 문자열"
formatted = format(b, "^20s") // 중앙에 값을 표시하는 ^ 사용
print(formatted)
Better way)
key = "my_var"
value = 1.234
formatted = "{} = {}".format(key, value)
print(formatted)
print(type(formatted))
파이썬 문자열 변환 str() 과 repr()의 차이점
repr() : __repr__ 메서드를 호출할 때 사용합니다.
시스템(python interpreter)가 해당 객체를 인식할 수 있는 공식적인 문자열로 나타내 줄때 사용하는 것이다.
str() : 사용자가 보기 쉬운 형태로 보여줄 때 사용하는 것이다.
자세한 예제가 있으므로, 참고 바랍니다.
파이썬 repr() 함수 - str()과의 차이점
본 포스팅에서는 Python의 repr() 함수를 알아보겠습니다. repr() 함수는 변수 또는 객체의 고유 표기 정...
blog.naver.com
'Python > CLEAN CODE' 카테고리의 다른 글
[ CLEAN CODE ] Dictionary defaultdict, Closure in local function? (1) | 2023.03.14 |
---|---|
[ CLEAN CODE ] 왈러스 연산자, ZIP, Packing, Unpacking? (0) | 2023.03.13 |
[ CLEAN CODE ] Clean Python, *args, **kwargs? (0) | 2023.01.25 |
[ CLEAN CODE ] Clean Python, Numpy with Linear Algebra (0) | 2023.01.21 |
[ CLEAN CODE ] Clean Python, broadcast_to, linspace란? (0) | 2023.01.21 |