C.W.K.
Stream
Lesson 03 of 08 · published

String — 네 형태, 한 규칙 (항상 quote)

~10 min · toml, strings

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

TOML string 은 항상 quote 입어

Basic string — 큰따옴표 + escape

"hello\nworld". 같은 JSON 스타일 escape (\n \t \\ \" \uXXXX). 짧은 string 의 기본.

멀티라인 basic string — 큰따옴표 세 개

""" line one\nline two """. Escape 작동; 줄 끝의 \ 가 다음 공백 trim, 진짜 줄바꿈 안 삽입하고 긴 줄 깨는 데 유용.

Literal string — 작은따옴표, escape 없음

'C:\Users\Pippa' 가 정확히 그 문자들. 백슬래시 해석 없음, 특수 의미 없음. Windows 경로와 regex 패턴에 완벽.

멀티라인 literal string — 작은따옴표 세 개

'''line one\nline two'''. 무엇을 쓰든 파서가 byte-for-byte 보존 (열린 fence 직후의 leading 줄바꿈만 trim).

원칙: 경로, regex, Windows 스타일 백슬래시엔 literal string (작은따옴표) — escape 없음 규칙이 오타 클래스 전체 제거. \n, Unicode escape, 보간 필요할 땐 basic string (큰따옴표). 내용 자체가 멀티라인일 때 멀티라인 형태.

Code

네 string 형태 모두·toml
basic     = "with \"escapes\" and \u00e9 and \n newline"
literal   = 'C:\Users\Pippa\config.txt'

block_basic = """
This is
multi-line basic. \u00e9 works,
and backslash-newline (\) at end of a line\
folds away.
"""

block_literal = '''
This is multi-line literal.
No escapes. The exact bytes you see
are what the parser delivers.
'''
Windows 경로 — literal 이김·toml
# 고통: 모든 백슬래시 두 배
basic_path = "C:\\Users\\Pippa\\.config\\app.toml"

# 깨끗: literal string, escape 없음
literal_path = 'C:\Users\Pippa\.config\app.toml'
멀티라인 basic 의 줄 연결·toml
# \ 없으면 string 이 literal 줄바꿈 포함:
verbose = """
Line one and line two with a real newline between them.
"""

# 줄 끝의 \ 로 줄바꿈 + leading 공백 trim
folded = """
Line one and line two \
  joined as one logical line.
"""
# folded == "Line one and line two joined as one logical line.\n"

External links

Exercise

네 config 값 작성: Windows 경로, 백슬래시 든 regex 패턴, 멀티라인 shell script, Unicode emoji escape 든 한 줄 인사. 각각 맞는 string 형태로. tomllib/tomli 로 파싱하고 각 값이 의도와 일치 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.