-
1. 기본 문법Python/Grammar 2022. 11. 28. 22:43
# 세미콜론
한 줄에 여러 구문을 사용할 때 세미콜론을 붙인다. 대부분의 프로그래밍 언어들은 구문이 끝날 때 세미콜론을 붙여야하지만 파이썬은 세미콜론을 붙이지 않아도 문법 에러가 발생하지 않는다.
EX)
print('Hello'); print('Python')
# 공백
파이썬 코딩 스타일 가이드(PEP 8)에서는 공백 4칸으로 규정하고 있어 공백 4칸을 사용하는 것이 좋으나 공백 2칸, 탭 1칸을 사용해도 잘 동작한다. 단, 같은 블록은 들여쓰기 칸 수가 같아야 하고 공백과 탭 문자를 섞어쓰면 안 된다.
# 코드 블록
파이썬은 들여쓰기를 기준으로 코드 블록을 구성한다.
EX)
count = 0 # 코드 블록 1 while count < 10: # 코드 블록 1 count += 1 # 코드 블록 2 print(count) # 코드 블록 2
'Python > Grammar' 카테고리의 다른 글
6. 문자열 사용하기 (0) 2022.11.30 5. 불과 비교, 논리 연산자 알아보기 (0) 2022.11.30 4. 출력 방법 알아보기 (0) 2022.11.29 3. 변수와 입력 사용하기 (0) 2022.11.29 2. 숫자 계산하기 (0) 2022.11.28