본문 바로가기
파이썬(Python)

[Python] 이스케이프 문자

by Yeah_D 2023. 1. 8.

 '이스케이프 문자'란?

이스케이프 문자란, 뒤따르는 문자의 뜻을 바꾸는 데 사용되는 일련의 특수문자이다.

파이썬에서 사용되는 이스케이프 문자는 아래와 같다.

이스케이프 문자 출력되는 문자
\\ 백슬래시(\) 
\' 작은 따옴표(')
\" 큰 따옴표(")
\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

댓글