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.
참고
'기술(Tech, IT) > 파이썬(Python)' 카테고리의 다른 글
[Tech, Python] re.compile() (0) | 2024.03.08 |
---|---|
[Tech, Python] re.escape (0) | 2024.03.02 |
[Python] SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (0) | 2024.01.06 |
[Python] pickle (0) | 2023.12.28 |
[Python] 링크드 리스트 구현 - 1 (Singly Linked List) (0) | 2023.10.14 |