'이스케이프 문자'란?
이스케이프 문자란, 뒤따르는 문자의 뜻을 바꾸는 데 사용되는 일련의 특수문자이다.
파이썬에서 사용되는 이스케이프 문자는 아래와 같다.
이스케이프 문자 | 출력되는 문자 |
\\ | 백슬래시(\) |
\' | 작은 따옴표(') |
\" | 큰 따옴표(") |
\n | 줄 바꿈 |
\t | 탭 |
사용 예시
백슬래시 출력
>>> sentence = "This is \\."
>>> print(sentence)
This is \.
작은 따옴표 출력
>>> sentence = "don\'t touch me"
>>> print(sentence)
don't touch me
큰 따옴표 출력
>>> sentence = "He said \"Hello\""
>>> print(sentence)
He said "Hello"
줄 바꿈
>>> sentence = "First\nSecond"
>>> print(sentence)
First
Second
탭
>>> sentence = "First\tSecond\tThird"
>>> print(sentence)
First Second Third
'파이썬(Python)' 카테고리의 다른 글
[Python] 지역변수와 전역변수 (0) | 2023.01.10 |
---|---|
[Python] 반복문 (for문, while문) (0) | 2023.01.09 |
[Python] 산술연산자 함수 정리 (0) | 2022.09.02 |
[Python] input(), int(), float(), str(), type() 함수 정리 (0) | 2022.08.30 |
[Python] 변수와 상수 차이 (0) | 2022.08.29 |
댓글