기술(Tech, IT)/파이썬(Python)
[Python] raw strings
Daniel803
2024. 1. 7. 14:38
s = 'C:\Users\Name\Folder'
와 같이 s라는 일반 string(normal string) 앞에 r 또는 R을 붙여 raw string을 만들 수 있다.
raw_s = r"C:\Users\Name\Folder"
raw string은 '\' (백슬래시)로 인해 특별한 문자열로 인식되는 '\n', '\t', '\U' 등과 같은 문자열을 글자 그대로의 문자열로 인식하도록 한다. 아래는 Python 공식 홈페이지의 설명이다.
: Both string and bytes literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and treat backslashes as literal characters. As a result, in string literals, '\U' and '\u' escapes in raw strings are not treated specially.
참고
반응형