string â ì¼ë°ì ì¸ ë¬¸ìì´ ì°ì°Â¶
Source code: Lib/string/__init__.py
문ìì´ ìì¶
ì´ ëª¨ëì ì ìë ììë ë¤ìê³¼ ê°ìµëë¤:
- string.ascii_letters¶
ìëì ëì¤ë
ascii_lowercaseìascii_uppercaseìì를 ì´ì´ë¶ì¸ ê²ì ëë¤. ì´ ê°ì ë¡ì¼ì¼ì ìì¡´ì ì´ì§ ììµëë¤.
- string.ascii_lowercase¶
ì문ì
'abcdefghijklmnopqrstuvwxyz'. ì´ ê°ì ë¡ì¼ì¼ì ìì¡´ì ì´ì§ ìê³ ë³ê²½ëì§ ììµëë¤.
- string.ascii_uppercase¶
ë문ì
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. ì´ ê°ì ë¡ì¼ì¼ì ìì¡´ì ì´ì§ ìê³ ë³ê²½ëì§ ììµëë¤.
- string.digits¶
문ìì´
'0123456789'.
- string.hexdigits¶
문ìì´
'0123456789abcdefABCDEF'.
- string.octdigits¶
문ìì´
'01234567'.
- string.punctuation¶
Cë¡ì¼ì¼ìì 구ëì 문ìë¡ ê°ì£¼íë ASCII 문ìì 문ìì´:!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~.
- string.printable¶
íì´ì¬ì´ ì¸ìí ì ìë ê²ì¼ë¡ ê°ì£¼íë ASCII 문ìì 문ìì´.
digits,ascii_letters,punctuation,whitespaceì ì¡°í©ì ëë¤.ì°¸ê³
By design,
string.printable.isprintable()returnsFalse. In particular,string.printableis not printable in the POSIX sense (see LC_CTYPE).
- string.whitespace¶
공백ì¼ë¡ ê°ì£¼íë 모ë ASCII 문ì를 í¬í¨íë 문ìì´. ì¬ê¸°ìë ì¤íì´ì¤, í, ì¤ ë°ê¿, ìºë¦¬ì§ 리í´, ì¸ë¡ í ë° í¼ í¼ë 문ìê° í¬í¨ë©ëë¤.
Custom string formatting¶
The built-in string class provides the ability to do complex variable
substitutions and value formatting via the format() method described in
PEP 3101. The Formatter class in the string module allows
you to create and customize your own string formatting behaviors using the same
implementation as the built-in format() method.
- class string.Formatter¶
Formatterí´ëì¤ìë ë¤ìê³¼ ê°ì ê³µê° ë©ìëê° ììµëë¤:- format(format_string, /, *args, **kwargs)¶
기본 API ë©ìëì ëë¤. í¬ë§· 문ìì´ê³¼ ììì ìì¹ ë° í¤ìë ì¸ìì ì§í©ì ë°ìë¤ì ëë¤. ì´ê²ì
vformat()ì í¸ì¶íë ëí¼ì¼ ë¿ì ëë¤.ë²ì 3.7ìì ë³ê²½: í¬ë§· 문ìì´ ì¸ìë ì´ì ìì¹ ì ì©ì ëë¤.
- vformat(format_string, args, kwargs)¶
ì´ í¨ìë ì¤ì í¬ë§· ìì ì ìíí©ëë¤.
*argsì**kwargs문ë²ì ì¬ì©íì¬ ëì ë리를 ê°ë³ì ì¸ ì¸ìë¡ ì¸ í¨í¹í í ë¤ì í¨í¹íë ëì 미리 ì ìë ì¸ì ëì ë리를 ì ë¬íê³ ì íë ê²½ì°ë¥¼ ìí´ ë³ëì í¨ìë¡ ë ¸ì¶í©ëë¤.vformat()ì í¬ë§· 문ìì´ì 문ì ë°ì´í°ì ì¹í íëë¡ ë¶ë¦¬íë ìì ì ìíí©ëë¤. ìëì ì¤ëª ë ë¤ìí ë©ìë를 í¸ì¶í©ëë¤.
ì´ì ëí´,
Formatterë ìë¸ í´ëì¤ì ìí´ ëì²´ë 목ì ì¼ë¡ ë§ì ë©ìë를 ì ìí©ëë¤:- parse(format_string)¶
format_stringì 루ííë©´ì íí (literal_text, field_name, format_spec, conversion) ì ì´í°ë¬ë¸ì ë°íí©ëë¤. ì´ê²ì
vformat()ì´ ë¬¸ìì´ì 리í°ë´ í ì¤í¸ì ì¹í íëë¡ ëëë ë° ì¬ì©í©ëë¤.The values in the tuple conceptually represent a span of literal text followed by a single replacement field. If there is no literal text (which can happen if two replacement fields occur consecutively), then literal_text will be a zero-length string. If there is no replacement field, then the values of field_name, format_spec and conversion will be
None. The value of field_name is unmodified and auto-numbering of non-numbered positional fields is done byvformat().
- get_field(field_name, args, kwargs)¶
Given field_name, convert it to an object to be formatted. Auto-numbering of field_name returned from
parse()is done byvformat()before calling this method. Returns a tuple (obj, used_key). The default version takes strings of the form defined in PEP 3101, such as â0[name]â or âlabel.titleâ. args and kwargs are as passed in tovformat(). The return value used_key has the same meaning as the key parameter toget_value().
- get_value(key, args, kwargs)¶
ì§ì ë íëì ê°ì ê°ì ¸ìµëë¤. key ì¸ìë ì ì ëë 문ìì´ì ëë¤. ì ìì ê²½ì°, args ì ìë ìì¹ ì¸ìì ì¸ë±ì¤ë¥¼ ëíë ëë¤; 문ìì´ì¸ ê²½ì°, kwargs ì ìë ì´ë¦ìë ì¸ì를 ëíë ëë¤.
args ë§¤ê° ë³ìë
vformat()ì ìì¹ ì¸ì 목ë¡ì¼ë¡ ì¤ì ëê³ , kwargs ë§¤ê° ë³ìë í¤ìë ì¸ì ëì ëë¦¬ë¡ ì¤ì ë©ëë¤.ë³µí© íë ì´ë¦ì ê²½ì°, ì´ë¬í í¨ìë íë ì´ë¦ì 첫 ë²ì§¸ êµ¬ì± ììì ëí´ìë§ í¸ì¶ë©ëë¤; íì êµ¬ì± ììë ì¼ë° ì´í¸ë¦¬ë·°í¸ ë° ì¸ë±ì± ì°ì°ì íµí´ ì²ë¦¬ë©ëë¤.
ê·¸ëì ì를 ë¤ì´, íë ííì â0.nameâ ì
get_value()ê° key ì¸ì 0ì¼ë¡ í¸ì¶ëëë¡ í©ëë¤.nameì´í¸ë¦¬ë·°í¸ëget_value()ê° ë°íí íì ë´ì¥getattr()í¨ì를 í¸ì¶íì¬ ì¡°íí©ëë¤.ì¸ë±ì¤ ëë í¤ìëê° ì¡´ì¬íì§ ìë í목ì 참조íë©´,
IndexErrorëKeyErrorê° ë°ìí©ëë¤.
- check_unused_args(used_args, args, kwargs)¶
ìíë ê²½ì° ì¬ì©íì§ ìë ì¸ì를 ê²ì¬íëë¡ êµ¬íí©ëë¤. ì´ í¨ìì ëí ì¸ìë í¬ë§· 문ìì´ìì 참조ëë 모ë ì¸ì í¤ì ì§í©ê³¼ (ìì¹ ì¸ìì ê²½ì° ì ì, ì´ë¦ìë ì¸ìì ê²½ì° ë¬¸ìì´), vformat ì¼ë¡ ì ë¬ë args ì kwargs ì ëí 참조ì ëë¤. ì¬ì©ëì§ ìì ì¸ìì ì§í©ì ì´ ë§¤ê° ë³ìë¤ë¡ ê³ì°í ì ììµëë¤.
check_unused_args()ë ê²ì¬ê° ì¤í¨í ê²½ì° ìì¸ë¥¼ ë°ììí¬ ê²ì¼ë¡ ê°ì í©ëë¤.
- format_field(value, format_spec)¶
format_field()ë ë¨ìí ì ìformat()ë´ì¥ í¨ì를 í¸ì¶í©ëë¤. ìë¸ í´ëì¤ê° ì¬ì ìí ì ìëë¡ ë©ìëê° ì ê³µë©ëë¤.
- convert_field(value, conversion)¶
(
get_field()ê° ë°íí) ê°(value)ì (parse()ë©ìëê° ë°ííë ííì ìë ê²ê³¼ ê°ì) 주ì´ì§ ë³í ì í(conversion)ì¼ë¡ ë³íí©ëë¤. 기본 ë²ì ì âsâ (str), ârâ (repr) ë° âaâ (ascii) ë³í ì íì ì¸ìí©ëë¤.
Format string syntax¶
The str.format() method and the Formatter class share the same
syntax for format strings (although in the case of Formatter,
subclasses can define their own format string syntax). The syntax is
related to that of formatted string literals and
template string literals, but it is less sophisticated
and, in particular, does not support arbitrary expressions in interpolations.
í¬ë§· 문ìì´ìë ì¤ê´í¸ {} ë¡ ëë¬ì¸ì¸ âì¹í íëâ ê° ë¤ì´ ììµëë¤. ì¤ê´í¸ ìì í¬í¨ëì§ ìì ê²ì 리í°ë´ í
ì¤í¸ë¡ ê°ì£¼íë©° ë³ê²½ëì§ ìê³ ê·¸ëë¡ ì¶ë ¥ì¼ë¡ ë³µì¬ë©ëë¤. 리í°ë´ í
ì¤í¸ì ì¤ê´í¸ë¥¼ í¬í¨í´ì¼ íë ê²½ì°, ì¤ë³µì¼ë¡ ì´ì¤ì¼ì´í í ì ììµëë¤: {{ ì }}.
ì¹í íëì 문ë²ì ë¤ìê³¼ ê°ìµëë¤:
replacement_field: "{" [field_name] ["!"conversion] [":"format_spec] "}" field_name:arg_name("."attribute_name| "["element_index"]")* arg_name: [identifier|digit+] attribute_name:identifierelement_index:digit+ |index_stringindex_string: <any source character except "]"> + conversion: "r" | "s" | "a" format_spec:format-spec:format_spec
ë íìì ì¸ ì©ì´ë¡, ì¹í íëë field_name ì¼ë¡ ììí ì ìëë°, ê°ì´ í¬ë§·ëì´ ì¶ë ¥ì ì¹í íë ëì ì½ì
ë ê°ì²´ë¥¼ ì§ì í©ëë¤. field_name ë¤ììë ì íì ì¼ë¡ ëëí '!' ê° ìì ì¤ë conversion íëì ì½ë¡ ':' ì´ ìì ì¤ë format_spec ì´ ìµëë¤. ì´ ê°ì ì¹í ê°ì ëí´ ê¸°ë³¸ê°ì´ ìë í¬ë§·ì ì§ì í©ëë¤.
Format specification mini-language ì¹ì ì ì°¸ê³ íììì¤.
field_name ìì²´ë ì«ìë í¤ìëì¸ arg_name ì¼ë¡ ììí©ëë¤. ì«ìë©´ ìì¹ ì¸ì를 ëíë´ê³ , í¤ìëë©´ ì´ë¦ì´ ìë í¤ìë ì¸ì를 ëíë
ëë¤. arg_nameì 문ìì´ì str.isdecimal()ì í¸ì¶íì ë ì°¸ì ë°ííë¤ë©´ ì«ìë¡ ì·¨ê¸ë©ëë¤. í¬ë§· 문ìì´ì ì«ì arg_nameì´ 0, 1, 2, ⦠ìì¼ë¡ ëì´ëë ê²½ì°, (ì¼ë¶ê° ìëë¼) ì ë¶ ìëµ í ì ìì¼ë©° ì«ì 0, 1, 2, â¦ì´ ììëë¡ ìë ì½ì
ë©ëë¤. arg_name ì´ ë°ì´íë¡ ë¶ë¦¬ëì´ ìì§ ì기 ë문ì, í¬ë§· 문ìì´ ë´ìì ììì ëì
ë리 í¤(ì를 ë¤ì´, '10' ì´ë ':-]')를 ì§ì í ì ììµëë¤. arg_name ë¤ììë ì í ìë ê°ìì ì¸ë±ì¤ë ì´í¸ë¦¬ë·°í¸ ííìì´ ì¬ ì ììµëë¤. '.name' ííì ííìì getattr()ì ì¬ì©íì¬ ì´ë¦ìë ì´í¸ë¦¬ë·°í¸ë¥¼ ì ííë ë°ë©´, '[index]' ííì ííìì __getitem__() ì ì¬ì©í´ì ì¸ë±ì¤ ì¡°í를 í©ëë¤.
ë²ì 3.1ìì ë³ê²½: ìì¹ ì¸ì ì§ì ìë str.format() ìì ìëµ í ì ììµëë¤. ê·¸ëì, '{} {}'.format(a, b) ë '{0} {1}'.format(a, b) ê³¼ ëë±í©ëë¤.
ë²ì 3.4ìì ë³ê²½: ìì¹ ì¸ì ì§ì ìë Formatterìì ìëµ í ì ììµëë¤.
ëª ê°ì§ ê°ë¨í í¬ë§· 문ìì´ ìì :
"First, thou shalt count to {0}" # 첫ë²ì§¸ ìì¹ ì¸ì를 참조í©ëë¤
"Bring me a {}" # 묵ìì ì¼ë¡ 첫ë²ì§¸ ìì¹ ì¸ì를 참조í©ëë¤
"From {} to {}" # "From {0} to {1}" ê³¼ ê°ìµëë¤
"My quest is {name}" # í¤ìë ì¸ì 'name' ì 참조í©ëë¤
"Weight in tons {0.weight}" # 첫ë²ì§¸ ìì¹ ì¸ìì 'weight' ì´í¸ë¦¬ë·°í¸
"Units destroyed: {players[0]}" # í¤ìë ì¸ì 'players' ì 첫ë²ì§¸ ìì.
conversion íëë í¬ë§¤í
ì ì í ì½ì´ì
ì ì¼ì¼íµëë¤. ë³´íµì, ê°ì í¬ë§¤í
íë ìì
ì ê° ìì²´ì __format__() ë©ìëì ìí´ ìíë©ëë¤. ê·¸ë¬ë ì´ë¤ ê²½ì°ìë í ìì ì í¬ë§¤í
ì ì를 무ìíê³ ë¬¸ìì´ë¡ í¬ë§·ëëë¡ ê°ì í íìê° ììµëë¤. __format__() ì í¸ì¶í기 ì ì ê°ì 문ìì´ë¡ ë³ííë©´, ì¼ë°ì ì¸ í¬ë§¤í
ë
¼ë¦¬ê° 무ìë©ëë¤.
íì¬ ì¸ ê°ì§ ë³í íëê·¸ê° ì§ìë©ëë¤: '!s' ë ê°ì str() ì í¸ì¶íê³ , '!r' ì ê°ì repr() ì í¸ì¶íê³ , '!a' ë ê°ì ascii() 를 í¸ì¶í©ëë¤.
ëª ê°ì§ ì:
"Harold's a clever {0!s}" # 먼ì ì¸ìì str() ì í¸ì¶í©ëë¤
"Bring out the holy {name!r}" # 먼ì ì¸ìì repr() ì í¸ì¶í©ëë¤
"More {!a}" # 먼ì ì¸ìì ascii() 를 í¸ì¶í©ëë¤
format_spec íëìë ê°ì íìíë ë°©ë²ì ëí ëª ì¸ê° í¬í¨ëì´ ìëë°, íë ëë¹, ì ë ¬, ì±ì, ìì§ ì ë°ë ë±ì´ í¬í¨ë©ëë¤. ê° ê° íì ìì²´ âí¬ë§¤í 미ë ì¸ì´â ëë format_spec ì í´ìì ì ì í ì ììµëë¤.
ëë¶ë¶ì ë´ì¥íì ë¤ì ì ìì ì¤ëª íë ê³µíµ í¬ë§¤í 미ë ì¸ì´ë¥¼ ì§ìí©ëë¤.
A format_spec íëë ê·¸ ìì ì¤ì²©ë ì¹í íë를 í¬í¨í ìë ììµëë¤. ì´ë¬í ì¤ì²© ë ì¹í íëìë íë ì´ë¦, ë³í íëê·¸ ë° í¬ë§· ëª ì¸ê° í¬í¨ë ì ìì§ë§, ë ê¹ì ì¤ì²©ì íì©ëì§ ììµëë¤. format_spec ë´ì ì¹í íëë format_spec 문ìì´ì´ í´ìë기 ì ì ì¹íë©ëë¤. ì´ë ê² í´ì ê°ì í¬ë§¤í ì ëì ì¼ë¡ ì§ì í ì ìê² í©ëë¤.
ëª ê°ì§ ìì ë í¬ë§· ìì ì¹ì ì ë³´ììì¤.
Format specification mini-language¶
âFormat specificationsâ are used within replacement fields contained within a
format string to define how individual values are presented (see
Format string syntax, í¬ë§· 문ìì´ ë¦¬í°ë´, and t-strings).
They can also be passed directly to the built-in
format() function. Each formattable type may define how the format
specification is to be interpreted.
ëë¶ë¶ì ë´ì¥íì í¬ë§· ëª ì¸ì ëí´ ë¤ì ìµì ì 구ííì§ë§, ì¼ë¶ í¬ë§· ìµì ì ì«ì íììë§ ì§ìë©ëë¤.
ì¼ë°ì ì¸ ê´ë¡ë ë¹ í¬ë§· ëª
ì¸ê° ê°ì str() ì í¸ì¶í ê²ê³¼ ê°ì 결과를 ë§ëë ê²ì
ëë¤. ë¹ì´ ìì§ ìì í¬ë§· ëª
ì¸ë ë³´íµ ê²°ê³¼ë¥¼ ìì í©ëë¤.
íì¤ í¬ë§· ì§ì ì ì ì¼ë°ì ì¸ íìì ë¤ìê³¼ ê°ìµëë¤:
format_spec: [options][width_and_precision][type] options: [[fill]align][sign]["z"]["#"]["0"] fill: <any character> align: "<" | ">" | "=" | "^" sign: "+" | "-" | " " width_and_precision: [width_with_grouping][precision_with_grouping] width_with_grouping: [width][grouping] precision_with_grouping: "." [precision][grouping] | "."groupingwidth:digit+ precision:digit+ grouping: "," | "_" type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
ì í¨í align ê°ì´ ì§ì ëë©´, fill 문ìê° ìì ëì¬ ì ìëë° ììì 문ìê° ë ì ìê³ , ìëµë ê²½ì°ìë ì¤íì´ì¤ê° 기본ê°ì¼ë¡ ì¬ì©ë©ëë¤. í¬ë§· 문ìì´ ë¦¬í°ë´ ììë str.format() ë©ìë를 ì¬ì©í ëë, 리í°ë´ ì¤ê´í¸(â{â ëë â}â)를 fill 문ìë¡ ì¬ì©í ì ììµëë¤. ê·¸ë¬ë, ì¤ì²©ë ì¹í íëë¡ ì¤ê´í¸ë¥¼ ì½ì
í ì ììµëë¤. ì´ ì íì format() í¨ììë ìí¥ì 미ì¹ì§ ììµëë¤.
ë¤ìí ì ë ¬ ìµì ì ì미ë ë¤ìê³¼ ê°ìµëë¤:
ìµì |
ì미 |
|---|---|
|
ì¬ì© ê°ë¥í ê³µê° ë´ìì íëê° ì¼ìª½ ì ë ¬ëëë¡ í©ëë¤ (ëë¶ë¶ ê°ì²´ìì ì´ê²ì´ 기본ê°ì ëë¤). |
|
ì¬ì© ê°ë¥í ê³µê° ë´ìì íëê° ì¤ë¥¸ìª½ ì ë ¬ëëë¡ í©ëë¤ (ì«ììì ì´ê²ì´ 기본ê°ì ëë¤). |
|
ì±ìì´ ë¶í¸ (ìë¤ë©´) ë¤ì, ì«ì ìì ì¤ëë¡ ê°ì í©ëë¤. ì´ê²ì â+000000120â íìì¼ë¡ íë를 ì¸ìíë ë° ì¬ì©ë©ëë¤. ì´ ì ë ¬ ìµì
ì |
|
ì¬ì© ê°ë¥í ê³µê° ë´ìì íë를 ê°ì´ë°ì ë°°ì¹í©ëë¤. |
ìµì íë ëë¹ê° ì ìëì§ ìì¼ë©´, íë ëë¹ë íì íë를 ì±ì¸ ë°ì´í°ì ê°ì í¬ê¸°ì´ë¯ë¡, ì ë ¬ ìµì ì ì´ ê²½ì° ìë¯¸ê° ììµëë¤.
sign ìµì ì ì«ì íìê²ë§ ì í¨íë©°, ë¤ì ì¤ íëì¼ ì ììµëë¤:
ìµì |
ì미 |
|---|---|
|
ììë¿ë§ ìëë¼ ìììë ë¶í¸ë¥¼ ì¬ì©í´ì¼ í¨ì ëíë ëë¤. |
|
ììì ëí´ìë§ ë¶í¸ë¥¼ ì¬ì©í´ì¼ í¨ì ëíë ëë¤ (ì´ê²ì´ 기본 ëìì ëë¤). |
ì¤íì´ì¤ |
ìììë ì í ì¤íì´ì¤ë¥¼ ì¬ì©íê³ , ìììë ë§ì´ëì¤ ë¶í¸ë¥¼ ì¬ì©í´ì¼ í¨ì ëíë ëë¤. |
The 'z' option coerces negative zero floating-point values to positive
zero after rounding to the format precision. This option is only valid for
floating-point presentation types.
ë²ì 3.11ìì ë³ê²½: 'z' ìµì
ì ì¶ê°íìµëë¤ (PEP 682 ë ë³´ì¸ì).
'#' ìµì
ì ë³íì âëì íìâ ì´ ì¬ì©ëëë¡ ë§ëëë¤. ëì íìì íë³ë¡ ë¤ë¥´ê² ì ìë©ëë¤. ì´ ìµì
ì ì ì, ì¤ìì ë³µìì íìê²ë§ ì í¨í©ëë¤. ì ìì ê²½ì°, ì´ì§ì, 8ì§ì ëë 16ì§ì ì¶ë ¥ì´ ì¬ì©ë ë, ì´ ìµì
ì ì¶ë ¥ê°ì ê°ê° ì ëì¬ '0b', '0o', '0x' ëë '0X' 를 ì¶ê°í©ëë¤. ì¤ìì ë³µììì ê²½ì°, ëì íìì ë³í ê²°ê³¼ì ììì ìë ì«ìê° ìì´ë íì ììì 문ìê° í¬í¨ëê² í©ëë¤. ë³´íµì, ììì 문ìë ê·¸ ë¤ì ì«ìê° ìë ê²½ì°ìë§ ë³í ê²°ê³¼ì ëíë©ëë¤. ì´ì ëí´, 'g' ë° 'G' ë³íì ê²½ì° ëì ë¶ë 0ì´ ê²°ê³¼ìì ì ê±°ëì§ ììµëë¤.
width ë ìµì ì´ íë ëë¹ë¥¼ ì ìíë ìì§ ì ìì¸ë°, ì ëì¬, 구ë¶ì ë° ë¤ë¥¸ í¬ë§¤í 문ìë¤ì í¬í¨í©ëë¤. ì§ì íì§ ìì¼ë©´, íë ëë¹ë ë´ì©ì ìí´ ê²°ì ë©ëë¤.
ëª
ìì ì ë ¬ì´ ì£¼ì´ì§ì§ ìì ë, width íë ìì '0' 문ì를 ë¶ì´ë©´ complex를 ì ì¸í ì«ì íì ëí´ ë¶í¸ë¥¼ ê³ ë ¤íë 0 ì±ìì ì¬ì©í ì ììµëë¤. ì´ê²ì '0' ì fill 문ìì '=' ì alignment ì íì ê°ë ê²ê³¼ ëë±í©ëë¤.
ë²ì 3.10ìì ë³ê²½: Preceding the width field by '0' no longer affects the default
alignment for strings.
precision ì íì ì í 'f'ì 'F'ì ê²½ì° ììì ë¤ì íìë ì릿ì를, 'g'ì 'G'ì ê²½ì° ììì ì, ë¤ë¡ íìí ì릿ì를 ëíë´ë ìì§ ì ìì
ëë¤. 문ìì´ íì ì íì ê²½ì° íëë ìµë íë í¬ê¸°ë¥¼ ëíë
ëë¤ - ì¦, íë ë´ì©ìì ëª ê°ì 문ìê° ì¬ì©ëëì§ ëíë
ëë¤. ì ì íì ì íìë precision ì´ íì©ëì§ ììµëë¤.
The grouping option after width and precision fields specifies a digit group separator for the integral and fractional parts of a number respectively. It can be one of the following:
ìµì |
ì미 |
|---|---|
|
ì ì íì ì í |
|
ì ì íì ì í |
ë¡ì¼ì¼ì ê³ ë ¤íë 구ë¶ìì ê²½ì°, ëì 'n' íì ì íì ì¬ì©íììì¤.
ë²ì 3.1ìì ë³ê²½: ',' ìµì
ì ì¶ê°íìµëë¤ (PEP 378 ë ë³´ì¸ì).
ë²ì 3.6ìì ë³ê²½: '_' ìµì
ì ì¶ê°íìµëë¤ (PEP 515 ë ë³´ì¸ì).
ë²ì 3.14ìì ë³ê²½: Support the grouping option for the fractional part.
ë§ì§ë§ì¼ë¡ type ì ë°ì´í°ë¥¼ íìíë ë°©ë²ì ê²°ì í©ëë¤.
ì¬ì© ê°ë¥í 문ìì´ íì ì íì ë¤ìê³¼ ê°ìµëë¤:
ì í
ì미
's'문ìì´ í¬ë§·. ì´ê²ì 문ìì´ì 기본 ì íì´ê³ ìëµë ì ììµëë¤.
ìì
's'ì ê°ìµëë¤.
ì¬ì© ê°ë¥í ì ì íì ì íì ë¤ìê³¼ ê°ìµëë¤:
ì í
ì미
'b'ì´ì§ íì. ì´ì§ë²ì¼ë¡ ì«ì를 ì¶ë ¥í©ëë¤.
'c'문ì. ì¸ìí기 ì ì ì ì를 í´ë¹ ì ëì½ë 문ìë¡ ë³íí©ëë¤.
'd'ìì§ ì ì. ìì§ë²ì¼ë¡ ì«ì를 ì¶ë ¥í©ëë¤.
'o'8ì§ íì. 8ì§ë²ì¼ë¡ ì«ì를 ì¶ë ¥í©ëë¤.
'x'16ì§ íì. 9ë³´ë¤ í° ì«ìì ê²½ì° ì문ì를 ì¬ì©íì¬ 16ì§ë²ì¼ë¡ ì«ì를 ì¶ë ¥í©ëë¤.
'X'16ì§ íì. 9ë³´ë¤ í° ì«ìì ê²½ì° ë문ì를 ì¬ì©íì¬ 16ì§ë²ì¼ë¡ ì«ì를 ì¶ë ¥í©ëë¤.
'#'ê° ì§ì ëë©´, ì ëì¬'0x'ë ë문ìë¡ ë³íëì´'0X'ë¡ íìë©ëë¤.
'n'ì«ì. ì´ë íì¬ ë¡ì¼ì¼ ì¤ì ì ì¬ì©íì¬ ì ì í ì«ì 그룹 구ë¶ì를 ì½ì íë¤ë ì ì ì ì¸íê³ ë
'd'ì ê°ìµëë¤.ìì
'd'ì ê°ìµëë¤.
ìì íì ì íì ëí´, ì ìë ìëì ëì´ë ë¶ë ììì íì ì íì¼ë¡ í¬ë§·ë ì ììµëë¤ ('n' ë° ìì ì ì¸). ê·¸ë ê² í ë, í¬ë§¤í
ì ì ì ì를 ë¶ë ììì ì«ìë¡ ë³íí기 ìí´ float() ê° ì¬ì©ë©ëë¤.
float ë° Decimal ê°ì ì¬ì©í ì ìë íì ì íì ë¤ìê³¼ ê°ìµëë¤:
ì í
ì미
'e'ê³¼íì í기ë². 주ì´ì§ ì ë°ë
pì ëí´, ì§ììì ê³ì를 구ë¶íë 문ì âeâ를 ì¬ì©íì¬ ê³¼íì í기ë²ì¼ë¡ ì«ì를 í¬ë§·í©ëë¤. ê³ìë ììì ìì í ì리ì ììì ë¤ìpì리를 ê°ì ¸ì, ì´p + 1ì í¨ ì릿ì를 ê°ìµëë¤. ì ë°ëê° ì§ì ëì§ ìì¼ë©´,floatì ê²½ì°ë ììì ë¤ì6ì«ìì ì ë°ë를 ì¬ì©íê³ ,Decimalì ê²½ì°ë 모ë ê³ì ì«ì를 íìí©ëë¤.p=0ì´ë©´,#ìµì ì ì¬ì©íì§ ìë í ììì ì ìëµë©ëë¤.For
float, the exponent always contains at least two digits, and is zero if the value is zero.
'E'ê³¼íì í기ë². êµ¬ë¶ ë¬¸ìë¡ ë문ì âEâ를 ì¬ì©íë¤ë ê²ì ì ì¸íê³
'e'ì ê°ìµëë¤.
'f'ê³ ì ììì í기ë². 주ì´ì§ ì ë°ë
pì ëí´, ììì ë¤ì ì íípìë¦¬ê° ìë ìì§ìë¡ ì«ì를 í¬ë§·í©ëë¤. ì ë°ëê° ì§ì ëì§ ìì¼ë©´,floatì ê²½ì°ë ììì ë¤ì6ì«ìì ì ë°ë를 ì¬ì©íê³ ,Decimalì ê²½ì°ë 모ë ê³ì ì«ì를 íìí ë§í¼ ì¶©ë¶í í° ì ë°ë를 ì¬ì©í©ëë¤.p=0ì´ë©´ ,#ìµì ì ì¬ì©íì§ ìë í ììì ì ìëµë©ëë¤.
'F'ê³ ì ììì í기ë².
'f'ì ê°ì§ë§,nanìNANì¼ë¡,inf를INFë¡ ë³íí©ëë¤.
'g'ë²ì© íì. 주ì´ì§ ì ë°ë
p >= 1ì ëí´, ì«ì를 ì í¨ ì«ìpë¡ ì리 ì¬ë¦¼ í ë¤ì, 결과를 í¬ê¸°ì ë°ë¼ ê³ ì ììì íìì´ë ê³¼í í기ë²ì¼ë¡ í¬ë§·í©ëë¤. ì ë°ë0ì ì ë°ë1ê³¼ ëë±íê² ì²ë¦¬ë©ëë¤.ì íí ê·ì¹ì ë¤ìê³¼ ê°ìµëë¤: íì ì í
'e'ì ì ë°ëp-1ë¡ í¬ë§·ë ê²°ê³¼ì ì§ìê°expë¼ê³ ê°ì íììì¤. ì´ë-m <= exp < pì´ë©´ (ì¬ê¸°ìmì floatìì -4ì´ê³Decimalì´ë©´ -6ì ëë¤), ì«ìë íì íì'f'ì ì ë°ëp-1-expë¡ í¬ë§·ë©ëë¤. ê·¸ë ì§ ìì¼ë©´, ì«ìë íì ì í'e'ì ì ë°ëp-1ë¡ í¬ë§·ë©ëë¤. ë ê²½ì° ì í¨íì§ ìì íí 0ì 모ë ì í¨ì«ìë¶ìì ì ê±°ëê³ , ë¤ì ë¨ììë ì«ìê° ìë¤ë©´'#'ìµì ì´ ì¬ì©ëì§ ìë í ììì ë ì ê±°ë©ëë¤.ì ë°ëê° ì§ì ëì§ ìì¼ë©´,
floatì ê²½ì°6ì í¨ ì릿ìì ì ë°ë를 ì¬ì©í©ëë¤.Decimalì ê²½ì°, ê²°ê³¼ ê³ìë ê°ì ê³ì ì«ìë¡ êµ¬ì±ë©ëë¤; ê³¼íì í기ë²ì ì ëê°ì´1e-6ë³´ë¤ ìì ê°ê³¼ ìµíì ì«ìì ì릿ê°ì´ 1ë³´ë¤ í° ê°ì ì¬ì©ëë©°, ê·¸ë ì§ ìì¼ë©´ ê³ ì ììì í기ë²ì´ ì¬ì©ë©ëë¤.ìê³¼ ìì 무íë, ìê³¼ ìì 0, nansë ì ë°ëì 무ê´íê² ê°ê°
inf,-inf,0,-0,nanì¼ë¡ í¬ë§·ë©ëë¤.
'G'ë²ì© íì. ì«ìê° ë무 커ì§ë©´
'E'ë¡ ì ííë ê²ì ì ì¸íê³'g'ì ê°ìµëë¤. 무íê³¼ NaN ì ííë ë문ìë¡ ë°ëëë¤.
'n'ì«ì. íì¬ ë¡ì¼ì¼ ì¤ì ì ì¬ì©íì¬ ì«ìì ì ìë¶ì ì ì í ì«ì 그룹 구ë¶ì를 ì½ì íë¤ë ì ì ì ì¸íë©´
'g'ì ê°ìµëë¤.
'%'ë°±ë¶ì¨. ì«ìì 100ì ê³±í´ì ê³ ì (
'f') íìì¼ë¡ íìí ë¤ì ë°±ë¶ì¨ 기í¸ë¥¼ ë¶ì ëë¤.ìì
floatì ê²½ì°,'g'ì íê³¼ ì ì¬íì§ë§, ê³ ì ììì í기ë²ì´ 결과를 í¬ë§·íëë° ì¬ì©ë ë, ììì ì´íë¡ ì ì´ë íëì ì«ì를 íì í¬í¨íê³ ,exp >= p - 1ì¼ ë ê³¼íì í기ë²ì¼ë¡ ì íí©ëë¤. ì ë°ëê° ì§ì ëì§ ìì¼ë©´, íìë 주ì´ì§ ê°ì ì¶©ì¤í íííë ë° íìí ë§í¼ í¬ê² ì¤ì ë©ëë¤.
Decimalì ê²½ì°, íì¬ ìì§ ì»¨í ì¤í¸ìcontext.capitalsê°ì ë°ë¼'g'ë'G'ì ê°ìµëë¤.ì ì²´ì ì¸ í¨ê³¼ë
str()ì ì¶ë ¥ì ë¤ë¥¸ í¬ë§· ìì ìì ìí´ ë³ê²½ë ê²ì²ë¼ ë§ëë ê²ì ëë¤.
The result should be correctly rounded to a given precision p of digits
after the decimal point. The rounding mode for float matches that
of the round() builtin. For Decimal, the rounding
mode of the current context will be used.
The available presentation types for complex are the same as those for
float ('%' is not allowed). Both the real and imaginary components
of a complex number are formatted as floating-point numbers, according to the
specified presentation type. They are separated by the mandatory sign of the
imaginary part, the latter being terminated by a j suffix. If the presentation
type is missing, the result will match the output of str() (complex numbers with
a non-zero real part are also surrounded by parentheses), possibly altered by
other format modifiers.
í¬ë§· ìì ¶
ì´ ì ì str.format() 문ë²ì ìì ìì %-í¬ë§¤í
ê³¼ì ë¹êµë¥¼ í¬í¨í©ëë¤.
ëë¶ë¶ì 문ë²ì´ ìì ì %-í¬ë§¤í
ê³¼ ì ì¬íë©°, {} ê° ì¶ê°ëê³ % ëì ë° : ì´ ì¬ì©ë©ëë¤. ì를 ë¤ì´, '%03.2f' ë '{:03.2f}' ë¡ ë²ìë ì ììµëë¤.
ì í¬ë§· 문ë²ì ë¤ì ìì ì ë³´ì´ë ê²ê³¼ ê°ì´ ìë¡ê³ ë¤ìí ìµì ë ì§ìí©ëë¤.
ìì¹ë¡ ì¸ì ì¡ì¸ì¤:
>>> '{0}, {1}, {2}'.format('a', 'b', 'c')
'a, b, c'
>>> '{}, {}, {}'.format('a', 'b', 'c') # 3.1+ ììë§
'a, b, c'
>>> '{2}, {1}, {0}'.format('a', 'b', 'c')
'c, b, a'
>>> '{2}, {1}, {0}'.format(*'abc') # ì¸ì ìíì¤ë¥¼ ì¸í¨í¹
'c, b, a'
>>> '{0}{1}{0}'.format('abra', 'cad') # ì¸ìì ì¸ë±ì¤ë ë°ë³µí ì ììµëë¤
'abracadabra'
ì´ë¦ì¼ë¡ ì¸ì ì¡ì¸ì¤:
>>> 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
'Coordinates: 37.24N, -115.81W'
>>> coord = {'latitude': '37.24N', 'longitude': '-115.81W'}
>>> 'Coordinates: {latitude}, {longitude}'.format(**coord)
'Coordinates: 37.24N, -115.81W'
ì¸ìì ì´í¸ë¦¬ë·°í¸ ì¡ì¸ì¤:
>>> c = 3-5j
>>> ('The complex number {0} is formed from the real part {0.real} '
... 'and the imaginary part {0.imag}.').format(c)
'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.'
>>> class Point:
... def __init__(self, x, y):
... self.x, self.y = x, y
... def __str__(self):
... return 'Point({self.x}, {self.y})'.format(self=self)
...
>>> str(Point(4, 2))
'Point(4, 2)'
ì¸ìì í목 ì¡ì¸ì¤:
>>> coord = (3, 5)
>>> 'X: {0[0]}; Y: {0[1]}'.format(coord)
'X: 3; Y: 5'
%s ê³¼ %r ëì²´:
>>> "repr() ì ë°ì´í를 íìíì§ë§: {!r}; str() ì ê·¸ë ì§ ììµëë¤: {!s}".format('test1', 'test2')
"repr() ì ë°ì´í를 íìíì§ë§: 'test1'; str() ì ê·¸ë ì§ ììµëë¤: test2"
í ì¤í¸ ì ë ¬ê³¼ ëë¹ ì§ì :
>>> '{:<30}'.format('left aligned')
'left aligned '
>>> '{:>30}'.format('right aligned')
' right aligned'
>>> '{:^30}'.format('centered')
' centered '
>>> '{:*^30}'.format('centered') # ì±ì 문ìë¡ '*' 를 ì¬ì©í©ëë¤
'***********centered***********'
%+f, %-f, % f ëì²´ì ë¶í¸ ì§ì :
>>> '{:+f}; {:+f}'.format(3.14, -3.14) # íì íìí©ëë¤
'+3.140000; -3.140000'
>>> '{: f}; {: f}'.format(3.14, -3.14) # ììë ì¤íì´ì¤ë¥¼ íìí©ëë¤
' 3.140000; -3.140000'
>>> '{:-f}; {:-f}'.format(3.14, -3.14) # ììë§ íìí©ëë¤ -- '{:f}; {:f}' ì ê°ìµëë¤
'3.140000; -3.140000'
%x, %o ëì²´ì ë¤ë¥¸ ì§ë²ì¼ë¡ ê° ë³í:
>>> # format ì ì´ì§ìë ì§ìí©ëë¤
>>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)
'int: 42; hex: 2a; oct: 52; bin: 101010'
>>> # with 0x, 0o, or 0b as prefix:
>>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)
'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'
ì¼íë ë°ì¤ì ì«ì 그룹 구ë¶ìë¡ ì¬ì©:
>>> '{:,}'.format(1234567890)
'1,234,567,890'
>>> '{:_}'.format(1234567890)
'1_234_567_890'
>>> '{:_b}'.format(1234567890)
'100_1001_1001_0110_0000_0010_1101_0010'
>>> '{:_x}'.format(1234567890)
'4996_02d2'
>>> '{:_}'.format(123456789.123456789)
'123_456_789.12345679'
>>> '{:.,}'.format(123456789.123456789)
'123456789.123,456,79'
>>> '{:,._}'.format(123456789.123456789)
'123,456,789.123_456_79'
ë°±ë¶ì¨ íí:
>>> points = 19
>>> total = 22
>>> 'Correct answers: {:.2%}'.format(points/total)
'Correct answers: 86.36%'
íë³ í¬ë§¤í ì¬ì©:
>>> import datetime as dt
>>> d = dt.datetime(2010, 7, 4, 12, 15, 58)
>>> '{:%Y-%m-%d %H:%M:%S}'.format(d)
'2010-07-04 12:15:58'
ì¸ì ì¤ì²©ê³¼ ë³´ë¤ ë³µì¡í ìì :
>>> for align, text in zip('<^>', ['left', 'center', 'right']):
... '{0:{fill}{align}16}'.format(text, fill=align, align=align)
...
'left<<<<<<<<<<<<'
'^^^^^center^^^^^'
'>>>>>>>>>>>right'
>>>
>>> octets = [192, 168, 0, 1]
>>> '{:02X}{:02X}{:02X}{:02X}'.format(*octets)
'C0A80001'
>>> int(_, 16)
3232235521
>>>
>>> width = 5
>>> for num in range(5,12):
... for base in 'dXob':
... print('{0:{width}{base}}'.format(num, base=base, width=width), end=' ')
... print()
...
5 5 5 101
6 6 6 110
7 7 7 111
8 8 10 1000
9 9 11 1001
10 A 12 1010
11 B 13 1011
Template strings ($-strings)¶
ì°¸ê³
The feature described here was introduced in Python 2.4;
a simple templating method based upon regular expressions.
It predates str.format(), formatted string literals,
and template string literals.
It is unrelated to template string literals (t-strings),
which were introduced in Python 3.14.
These evaluate to string.templatelib.Template objects,
found in the string.templatelib module.
í í릿 문ìì´ì PEP 292 ì ì¤ëª ë ëë¡ ë ê°ë¨í 문ìì´ ì¹íì ì ê³µí©ëë¤. í í릿 문ìì´ì 주ì ì¬ë¡ë êµì í(i18n)ì ëë¤. ì´ ë¬¸ë§¥ìì, ë ê°ë¨í 문ë²ê³¼ 기ë¥ì íì´ì¬ì ë¤ë¥¸ ë´ì¥ 문ìì´ í¬ë§¤í 기ë¥ë³´ë¤ ë²ìí기 ì½ê² ë§ë¤ê¸° ë문ì ëë¤. i18nì ìí´ í í릿 문ìì´ì 기ë°ì¼ë¡ 구ì¶ë ë¼ì´ë¸ë¬ë¦¬ì ìë flufl.i18n í¨í¤ì§ë¥¼ ë³´ììì¤.
í
í릿 문ìì´ì ë¤ì ê·ì¹ì ì¬ì©íì¬ $-ê¸°ë° ì¹íì ì§ìí©ëë¤:
$$ë ì´ì¤ì¼ì´íì ëë¤. ì´ê²ì íëì$ë¡ ì¹íë©ëë¤.$identifierë 매í í¤"identifier"ì ì¼ì¹íë ì¹í ì리 íìì를 ì§ì í©ëë¤. 기본ì ì¼ë¡,"identifier"ë ë°ì¤ì´ë ASCII ìíë²³ì¼ë¡ ììíë ëì문ì êµ¬ë¶ ìë ASCII ìì«ì(ë°ì¤ í¬í¨) 문ìì´ë¡ ì íë©ëë¤.$문ì ë¤ì 첫 ë²ì§¸ ë¹ ìë³ì 문ìë ì´ ì리 íìì ëª ì¸ë¥¼ ì¢ ë£í©ëë¤.${identifier}ë$identifierì ëë±í©ëë¤. ì í¨í ìë³ì 문ìê° ì리 íìì ë¤ì ì¤ì§ë§, ì리 íììì ì¼ë¶ê° ìëë©´ íìí©ëë¤, ê°ë ¹"${noun}ification".
문ìì´ì ë¤ë¥¸ ë°©ìì¼ë¡ $ ì´ ë±ì¥íë©´ ValueError ê° ë°ìí©ëë¤.
The string module provides a Template class that implements
these rules. The methods of Template are:
- class string.Template(template)¶
ìì±ìë í í릿 문ìì´ íë를 ë°ìë¤ì ëë¤.
- substitute(mapping={}, /, **kwds)¶
í í릿 ì¹íì ìííê³ , ì 문ìì´ì ë°íí©ëë¤. mapping ì í í릿ì ì리 íììì ì¼ì¹íë í¤ë¥¼ ê°ì§ ììì ëì ëë¦¬ë¥ ê°ì²´ì ëë¤. ëë, í¤ìëê° ì리 íììì¸ í¤ìë ì¸ì를 ì ê³µ í ì ììµëë¤. mapping ë° kwds ê° ëª¨ë ì ê³µëê³ ì¤ë³µì´ ìë ê²½ì°, kwds ì ì리 íììê° ì°ì í©ëë¤.
- safe_substitute(mapping={}, /, **kwds)¶
substitute()ì ë¹ì·íì§ë§, mapping ê³¼ kwds ì ì리 íììê° ìë ê²½ì°,KeyErrorìì¸ë¥¼ ë°ììí¤ì§ ìê³ ìë ì리 íììê° ê²°ê³¼ 문ìì´ì ê·¸ëë¡ ëíë©ëë¤. ëísubstitute()ìë ë¬ë¦¬,$ê° ì못 ì¬ì©ëë ê²½ì°ValueError를 ì¼ì¼í¤ë ëì ë¨ìí$를 ë°íí©ëë¤.ë¤ë¥¸ ìì¸ê° ì¬ì í ë°ìí ì ìì§ë§, ì´ ë©ìëê° íì ìì¸ë¥¼ ë°ììí¤ë ëì ì¬ì© ê°ë¥í 문ìì´ì ë°ííë ¤ê³ ìëí기 ë문ì âìì (safe)â íë¤ê³ í©ëë¤. ë¤ë¥¸ ì미ìì,
safe_substitute()ë ìì íë¤ê³ í ì ììµëë¤. 길 ìì(dangling) êµ¬ë¶ ê¸°í¸, ìì ì´ë£¨ì§ ìë ì¤ê´í¸, ì í¨í íì´ì¬ ìë³ìê° ìë ì리 íìì를 í¬í¨íë ì못ë í í릿ì ì¡°ì©í 무ìí기 ë문ì ëë¤.
- is_valid()¶
Returns
Falseif the template has invalid placeholders that will causesubstitute()to raiseValueError.Added in version 3.11.
- get_identifiers()¶
Returns a list of the valid identifiers in the template, in the order they first appear, ignoring any invalid identifiers.
Added in version 3.11.
Templateì¸ì¤í´ì¤ë ê³µê° ë°ì´í° ì´í¸ë¦¬ë·°í¸ë íë ì ê³µí©ëë¤:- template¶
ì´ê²ì ìì±ìì template ì¸ìë¡ ì ë¬ë ê°ì²´ì ëë¤. ì¼ë°ì ì¼ë¡, ë³ê²½í´ìë ì ëì§ë§, ì½ê¸° ì ì© ì¡ì¸ì¤ê° ê°ì ëì§ë ììµëë¤.
ë¤ìì Template ì¬ì© ë°©ë²ì ìì ëë¤:
>>> from string import Template
>>> s = Template('$who likes $what')
>>> s.substitute(who='tim', what='kung pao')
'tim likes kung pao'
>>> d = dict(who='tim')
>>> Template('Give $who $100').substitute(d)
Traceback (most recent call last):
...
ValueError: Invalid placeholder in string: line 1, col 11
>>> Template('$who likes $what').substitute(d)
Traceback (most recent call last):
...
KeyError: 'what'
>>> Template('$who likes $what').safe_substitute(d)
'tim likes $what'
ê³ ê¸ ì¬ì©ë²: Template ì ìë¸ í´ëì¤ë¥¼ íìíì¬, ì리 íìì 문ë², êµ¬ë¶ ê¸°í¸ ë¬¸ì ëë í
í릿 문ìì´ì íì±íëë° ì¬ì©ëë ì ì²´ ì ê·ìì ì¬ì©ì ì ì í ì ììµëë¤. ì´ë ê² íë ¤ë©´, ë¤ì í´ëì¤ ì´í¸ë¦¬ë·°í¸ë¥¼ ì¬ì ìí ì ììµëë¤:
delimiter â ì리 íìì를 ëì íë 구ë¶ì를 ëíë´ë 리í°ë´ 문ìì´ì ëë¤. 기본ê°ì
$ì ëë¤. 구íì²´ë íìí ë ì´ ë¬¸ìì´ìre.escape()를 í¸ì¶íë¯ë¡, ì´ ë¬¸ìì´ì ì ê·ìì´ ìëì´ì¼ í©ëë¤. ëí, í´ëì¤ ìì± íì 구ë¶ì를 ë³ê²½í ì ììµëë¤ (ì¦, ë¤ë¥¸ 구ë¶ìë ë°ëì ìë¸ í´ëì¤ì í´ëì¤ ì´ë¦ ê³µê°ì ì¤ì í´ì¼ í©ëë¤).idpattern â ì¤ê´í¸ë¡ ëë¬ì¸ì§ ìì ì리 íììì í¨í´ì ì¤ëª íë ì ê·ìì ëë¤. 기본ê°ì ì ê·ì
(?a:[_a-z][_a-z0-9]*)ì ëë¤. braceidpattern ì´Noneì¸ ê²½ì°, ì´ í¨í´ì ì¤ê´í¸ê° ìë ì리 íìììê²ë ì ì©ë©ëë¤.ì°¸ê³
기본 flags ê°
re.IGNORECASEì´ê¸° ë문ì, í¨í´[a-z]ë ë¹ ASCII 문ìì ì¼ì¹ í ì ììµëë¤. ì´ ë문ì ì ê·ììaíë그를 ì¬ì©íìµëë¤.ë²ì 3.7ìì ë³ê²½: braceidpattern ì ì¤ê´í¸ë¡ ì¸ì¬ìì ëì ê·¸ë ì§ ìì ë ì¬ì©ëë ë³ëì í¨í´ì ì ìíëë° ì¬ì©í ì ììµëë¤.
braceidpattern â idpattern ê³¼ ì ì¬íì§ë§, ì¤ê´í¸ë¡ ì¸ì¸ ì리 íììì ëí í¨í´ì ì¤ëª í©ëë¤. 기본ê°ì
Noneì¸ë°, idpattern ì ì¬ì©íë ê²ì ì미í©ëë¤ (ì¦, ê°ì í¨í´ì´ ì¤ê´í¸ê° ìì ëì ìì ë 모ë ì¬ì©ë©ëë¤). ì´ ê°ì 주면, ì¤ê´í¸ê° ìì ëì ìì ëì ì리 íììì ìë¡ ë¤ë¥¸ í¨í´ì ì ì í ì ììµëë¤.Added in version 3.7.
flags â ì¹í ì¸ìì ì¬ì©ëë ì ê·ìì ì»´íì¼í ë ì ì©ë ì ê·ì íëê·¸ì ëë¤. 기본ê°ì
re.IGNORECASEì ëë¤.re.VERBOSEê° íì íëê·¸ì ì¶ê°ëë¯ë¡, ì¬ì©ì ì ì idpattern ì ìì¸í ì ê·ìì ê·ì¹ì ë°ë¼ì¼ í©ëë¤.Added in version 3.2.
ëë, í´ëì¤ ì´í¸ë¦¬ë·°í¸ pattern ì ì¬ì ìíì¬ ì ì²´ ì ê·ì í¨í´ì ì ê³µ í ì ììµëë¤. ì´ë ê² íë ê²½ì°, ê°ì ë¤ ê°ì ì´ë¦ìë ìº¡ì² ê·¸ë£¹ì´ ìë ì ê·ì ê°ì²´ì¬ì¼ í©ëë¤. ìº¡ì² ê·¸ë£¹ì ìì ì ê³µë ê·ì¹ê³¼ í¨ê» ì í¨íì§ ìì ì리 íìì ê·ì¹ì í´ë¹í©ëë¤:
escaped â ì´ ê·¸ë£¹ì ì´ì¤ì¼ì´í ìíì¤ë¥¼ ì¼ì¹ìíµëë¤, ì를 ë¤ì´ 기본 í¨í´ìì
$$.named â ì´ ê·¸ë£¹ì ì¤ê´í¸ê° ìë ì리 íìì ì´ë¦ì ì¼ì¹í©ëë¤; ìº¡ì² ê·¸ë£¹ì 구ë¶ì를 í¬í¨í´ìë ì ë©ëë¤.
braced â ì´ ê·¸ë£¹ì ì¤ê´í¸ë¡ ë¬¶ì¸ ì리 íìì ì´ë¦ì ì¼ì¹ìíµëë¤; ìº¡ì² ê·¸ë£¹ì 구ë¶ìë ì¤ê´í¸ë¥¼ í¬í¨í´ìë ì ë©ëë¤.
invalid â ì´ ê·¸ë£¹ì ê·¸ ì¸ì 구ë¶ì í¨í´(ì¼ë°ì ì¼ë¡ ë¨ì¼ 구ë¶ì)ì ì¼ì¹ìí¤ê³ , ì ê·ìì ë§ì§ë§ì ëíëì¼ í©ëë¤.
The methods on this class will raise ValueError if the pattern matches
the template without one of these named groups matching.
ëì í¨ì¶
- string.capwords(s, sep=None)¶
ì¸ì를
str.split()ì ì¬ì©íì¬ ë¨ì´ë¡ ëëê³ ,str.capitalize()를 ì¬ì©íì¬ ê° ë¨ì´ì 첫 ê¸ì를 ë문ìë¡ ë§ë¤ê³ , ì´ë ê² ë§ë¤ì´ì§ ë¨ì´ë¤ìstr.join()ì ì¬ì©íì¬ ê²°í©í©ëë¤. ì íì ë ë²ì§¸ ì¸ì sep ê° ìê±°ëNoneì´ë©´, ì°ìë 공백 문ìë ë¨ì¼ ì¤íì´ì¤ë¡ ë°ëê³ ìë¤ ê³µë°±ì´ ì ê±°ë©ëë¤. ê·¸ë ì§ ìì¼ë©´ sep ê° ë¨ì´ë¥¼ ëëê³ í©ì¹ë ë° ì¬ì©ë©ëë¤.