PEP 8 이란?
PEP란 "Python Enhancement Proposal" 의 abbreviation으로
Python의 새로운 기능을 제안하거나 스타일 가이드 등이 제시된 문서임.

그 중에서 PEP 8은 일종의 Code Convention으로 코딩 스타일에 대한 권장임.
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
번역본: https://github.com/DongjunLee/PEP8_kor
GitHub - DongjunLee/PEP8_kor: PEP 8 -- Style Guide for Python Code (Korean)
PEP 8 -- Style Guide for Python Code (Korean). Contribute to DongjunLee/PEP8_kor development by creating an account on GitHub.
github.com
대표적인 내용
대표적인 내용은 다음과 같음.
- Indentation : 공백문자 4칸을 권장. (space 와 tab을 혼용하지 말 것)
- Single line은 최대 79자 정도
- 최상위 function과 class 정의는 2 line을 띄운 후 시작할 것.
- class 내에서 method를 정의할 때는 1줄씩 띄워 사용할 것.
- import statement는 가급적 python source file에서 가장 처음에 위치하도록 할 것.
- 여러 패키지의 import는 가급적 하나의 라인별로 분리해서 기재할 것.
- function, variable, attributes 는 가급적 lowercase와 underscore를 이용한 snake naming을 사용할 것.
- public attributes 의 경우 가급적 underscore로 시작해선 안됨.
- protected instance attribute의 경우 underscore로 시작하는 이름을 가질 것.
- private instance attribute의 경우 double underscore로 시작하는 이름을 가질 것.
참고로 flake 8 이라는 패키지를 설치하고 나면, PEP 8 에 맞게 코딩을 했는지를 검사해 줌.
같이 보면 좋은 자료들
https://ds31x.blogspot.com/2023/07/etc-naming-convention.html
[Etc] Naming Convention
Naming Convention은 프로그래밍에서 variable이나 class등의 이름을 짓는 일종의 약속이다. Camel Naming (or Camel Case) Java나 C++(MFC나 windows 대상인 경우)등에서는 Camel Naming ...
ds31x.blogspot.com
'Python' 카테고리의 다른 글
| [Python] Class로 수행시간 측정 decorator 만들기 (0) | 2023.08.18 |
|---|---|
| [Python] Decorator (1) | 2023.08.18 |
| [Python] asterisk * 사용하기 : unpacking, packing (1) | 2023.07.30 |
| [Python] while statement, break and continue: (0) | 2023.07.28 |
| [Python] if, elif, else statements (0) | 2023.07.28 |