{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. C 스타일 형식 문자열을 str.format과 쓰기보다는 f-문자열을 통한 인터폴레이션을 사용하라"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 형식화(formatting)는 미리 정의된 문자열에 데이터 값을 끼워 넣어서 사람이 보기 좋은 문자열로 저장하는 과정"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- % formatting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "이진수: 187, 십육진수: 3167\n"
     ]
    }
   ],
   "source": [
    "a = 0b10111011\n",
    "b = 0xc5f\n",
    "print('이진수: %d, 십육진수: %d' % (a, b))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "C 스타일 형식화의 문제점\n",
    "1. 형식화 식에서 오른쪽에 있는 tuple 내 데이터 값의 순서를 바꾸거나 값의 타입을 바꾸면 타입 변환이 불가능하므로 오류가 발생할 수 있다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my_var     = 1.23\n"
     ]
    }
   ],
   "source": [
    "key = 'my_var'\n",
    "value = 1.234\n",
    "formatted = '%-10s = %.2f' % (key, value)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "must be real number, not str",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-3438bf149d3e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mreordered_tuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'%-10s = %.2f'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: must be real number, not str"
     ]
    }
   ],
   "source": [
    "reordered_tuple = '%-10s = %.2f' % (value, key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "must be real number, not str",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-6-7391cce685e6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mreordered_string\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'%.2f = %-10s'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: must be real number, not str"
     ]
    }
   ],
   "source": [
    "reordered_string = '%.2f = %-10s' % (key, value)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 형식화를 하기 전에 값을 살짝 변경해야 한다면 식을 읽기가 매우 어려워 진다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#0: 아보카도       = 1.24\n",
      "#1: 바나나        = 2.50\n",
      "#2: 체리         = 15.00\n"
     ]
    }
   ],
   "source": [
    "pantry = [\n",
    "    ('아보카도', 1.24),\n",
    "    ('바나나', 2.5),\n",
    "    ('체리', 15),\n",
    "]\n",
    "for i, (item, count) in enumerate(pantry):\n",
    "    print('#%d: %-10s = %.2f' % (i, item, count))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#1: 아보카도       = 1\n",
      "#2: 바나나        = 2\n",
      "#3: 체리         = 15\n"
     ]
    }
   ],
   "source": [
    "for i, (item, count) in enumerate(pantry):\n",
    "    print('#%d: %-10s = %d' % (\n",
    "        i + 1,\n",
    "        item.title(),\n",
    "        round(count)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. 형식화 문자열에서 같은 값을 여러번 사용하고 싶다면 튜플에서 같은 값을 여러 번 반복해야 한다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "철수는 음식을 좋아해, 철수가 요리하는 모습을 봐요.\n"
     ]
    }
   ],
   "source": [
    "template = '%s는 음식을 좋아해, %s가 요리하는 모습을 봐요.'\n",
    "name = '철수'\n",
    "formatted = template % (name, name)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dongju Park\n"
     ]
    }
   ],
   "source": [
    "# title test\n",
    "test = 'dongju park'\n",
    "print(test.title())\n",
    "# 띄어쓰기 기준으로 문자 맨 앞글자를 대문자로 변경 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "위의 문제들 해결 방법\n",
    "1. 딕셔너리 이용"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my_var     = 1.23\n",
      "my_var     = 1.23\n",
      "my_var     = 1.23\n"
     ]
    }
   ],
   "source": [
    "key = 'my_var'\n",
    "value = 1.234\n",
    "\n",
    "old_way = '%-10s = %.2f' % (key, value)\n",
    "\n",
    "new_way = '%(key)-10s = %(value).2f' % {\n",
    "    'key': key, 'value': value} # 원래방식\n",
    "\n",
    "reordered = '%(key)-10s = %(value).2f' % {\n",
    "    'value': value, 'key': key} # 바꾼 방식\n",
    "\n",
    "print(old_way)\n",
    "print(new_way)\n",
    "print(reordered)\n",
    "\n",
    "assert old_way == new_way == reordered"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. 딕셔너리 이용"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "철수는 음식을 좋아해, 철수가 요리하는 모습을 봐요.\n",
      "철수는 음식을 좋아해, 철수가 요리하는 모습을 봐요.\n"
     ]
    }
   ],
   "source": [
    "template = '%s는 음식을 좋아해, %s가 요리하는 모습을 봐요.'\n",
    "name = '철수'\n",
    "\n",
    "before = template % (name, name) # 튜플\n",
    "template = '%(name)s는 음식을 좋아해, %(name)s가 요리하는 모습을 봐요.'\n",
    "after = template % {'name': name}\n",
    "\n",
    "print(before)\n",
    "print(after)\n",
    "\n",
    "assert before == after"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. 딕셔너리를 사용하면 오히려 복잡해짐 -> 네번째 문제가 됨"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#1: 아보카도       = 1\n",
      "#1: 아보카도       = 1\n",
      "#2: 바나나        = 2\n",
      "#2: 바나나        = 2\n",
      "#3: 체리         = 15\n",
      "#3: 체리         = 15\n"
     ]
    }
   ],
   "source": [
    "for i, (item, count) in enumerate(pantry):\n",
    "    before = '#%d: %-10s = %d' % (\n",
    "        i + 1,\n",
    "        item.title(),\n",
    "        round(count))\n",
    "    after = '#%(loop)d: %(item)-10s = %(count)d' % {\n",
    "        'loop': i + 1,\n",
    "        'item': item.title(),\n",
    "        'count': round(count),\n",
    "    }\n",
    "    \n",
    "    print(before)\n",
    "    print(after)\n",
    "    \n",
    "    assert before == after"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Today's soup is lentil.\n"
     ]
    }
   ],
   "source": [
    "soup = 'lentil'\n",
    "formatted = 'Today\\'s soup is %(soup)s.' % {'soup': soup}  # \\'를 보여주기 위해 일부러 원서 코드를 그대로 남겨둠\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Today's soup is lentil, buy one get two tongyoung oysters, and our special entrée is schnitzel.\n"
     ]
    }
   ],
   "source": [
    "menu = {\n",
    "    'soup': 'lentil',\n",
    "    'oyster': 'tongyoung',\n",
    "    'special': 'schnitzel',\n",
    "}\n",
    "template = ('Today\\'s soup is %(soup)s, '\n",
    "            'buy one get two %(oyster)s oysters, '\n",
    "            'and our special entrée is %(special)s.')\n",
    "formatted = template % menu\n",
    "print(formatted)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "가독성이 더 나빠지므로 더 나은 방법이 있어야 한다."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 내장 함수 format과 str.format"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "format 내장 함수를 통한 **고급 문자열 형식화**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1,234.57\n"
     ]
    }
   ],
   "source": [
    "a = 1234.5678\n",
    "formatted = format(a, ',.2f')\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*        my 문자열        *\n"
     ]
    }
   ],
   "source": [
    "b = 'my 문자열'\n",
    "formatted = format(b, '^20s')\n",
    "print('*', formatted, '*')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "str 타입에 format의 경우 위치 지정자 {}를 사용할 수 있다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my_var = 1.234\n"
     ]
    }
   ],
   "source": [
    "key = 'my_var'\n",
    "value = 1.234\n",
    "\n",
    "formatted = '{} = {}'.format(key, value)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "위치 지정자에는 콜론 뒤에 형식 지정자를 넣어 변환 할 수 있다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Format String Syntax\n",
      "********************\n",
      "\n",
      "The \"str.format()\" method and the \"Formatter\" class share the same\n",
      "syntax for format strings (although in the case of \"Formatter\",\n",
      "subclasses can define their own format string syntax).  The syntax is\n",
      "related to that of formatted string literals, but there are\n",
      "differences.\n",
      "\n",
      "Format strings contain “replacement fields” surrounded by curly braces\n",
      "\"{}\". Anything that is not contained in braces is considered literal\n",
      "text, which is copied unchanged to the output.  If you need to include\n",
      "a brace character in the literal text, it can be escaped by doubling:\n",
      "\"{{\" and \"}}\".\n",
      "\n",
      "The grammar for a replacement field is as follows:\n",
      "\n",
      "      replacement_field ::= \"{\" [field_name] [\"!\" conversion] [\":\" format_spec] \"}\"\n",
      "      field_name        ::= arg_name (\".\" attribute_name | \"[\" element_index \"]\")*\n",
      "      arg_name          ::= [identifier | digit+]\n",
      "      attribute_name    ::= identifier\n",
      "      element_index     ::= digit+ | index_string\n",
      "      index_string      ::= <any source character except \"]\"> +\n",
      "      conversion        ::= \"r\" | \"s\" | \"a\"\n",
      "      format_spec       ::= <described in the next section>\n",
      "\n",
      "In less formal terms, the replacement field can start with a\n",
      "*field_name* that specifies the object whose value is to be formatted\n",
      "and inserted into the output instead of the replacement field. The\n",
      "*field_name* is optionally followed by a  *conversion* field, which is\n",
      "preceded by an exclamation point \"'!'\", and a *format_spec*, which is\n",
      "preceded by a colon \"':'\".  These specify a non-default format for the\n",
      "replacement value.\n",
      "\n",
      "See also the Format Specification Mini-Language section.\n",
      "\n",
      "The *field_name* itself begins with an *arg_name* that is either a\n",
      "number or a keyword.  If it’s a number, it refers to a positional\n",
      "argument, and if it’s a keyword, it refers to a named keyword\n",
      "argument.  If the numerical arg_names in a format string are 0, 1, 2,\n",
      "… in sequence, they can all be omitted (not just some) and the numbers\n",
      "0, 1, 2, … will be automatically inserted in that order. Because\n",
      "*arg_name* is not quote-delimited, it is not possible to specify\n",
      "arbitrary dictionary keys (e.g., the strings \"'10'\" or \"':-]'\") within\n",
      "a format string. The *arg_name* can be followed by any number of index\n",
      "or attribute expressions. An expression of the form \"'.name'\" selects\n",
      "the named attribute using \"getattr()\", while an expression of the form\n",
      "\"'[index]'\" does an index lookup using \"__getitem__()\".\n",
      "\n",
      "Changed in version 3.1: The positional argument specifiers can be\n",
      "omitted for \"str.format()\", so \"'{} {}'.format(a, b)\" is equivalent to\n",
      "\"'{0} {1}'.format(a, b)\".\n",
      "\n",
      "Changed in version 3.4: The positional argument specifiers can be\n",
      "omitted for \"Formatter\".\n",
      "\n",
      "Some simple format string examples:\n",
      "\n",
      "   \"First, thou shalt count to {0}\"  # References first positional argument\n",
      "   \"Bring me a {}\"                   # Implicitly references the first positional argument\n",
      "   \"From {} to {}\"                   # Same as \"From {0} to {1}\"\n",
      "   \"My quest is {name}\"              # References keyword argument 'name'\n",
      "   \"Weight in tons {0.weight}\"       # 'weight' attribute of first positional arg\n",
      "   \"Units destroyed: {players[0]}\"   # First element of keyword argument 'players'.\n",
      "\n",
      "The *conversion* field causes a type coercion before formatting.\n",
      "Normally, the job of formatting a value is done by the \"__format__()\"\n",
      "method of the value itself.  However, in some cases it is desirable to\n",
      "force a type to be formatted as a string, overriding its own\n",
      "definition of formatting.  By converting the value to a string before\n",
      "calling \"__format__()\", the normal formatting logic is bypassed.\n",
      "\n",
      "Three conversion flags are currently supported: \"'!s'\" which calls\n",
      "\"str()\" on the value, \"'!r'\" which calls \"repr()\" and \"'!a'\" which\n",
      "calls \"ascii()\".\n",
      "\n",
      "Some examples:\n",
      "\n",
      "   \"Harold's a clever {0!s}\"        # Calls str() on the argument first\n",
      "   \"Bring out the holy {name!r}\"    # Calls repr() on the argument first\n",
      "   \"More {!a}\"                      # Calls ascii() on the argument first\n",
      "\n",
      "The *format_spec* field contains a specification of how the value\n",
      "should be presented, including such details as field width, alignment,\n",
      "padding, decimal precision and so on.  Each value type can define its\n",
      "own “formatting mini-language” or interpretation of the *format_spec*.\n",
      "\n",
      "Most built-in types support a common formatting mini-language, which\n",
      "is described in the next section.\n",
      "\n",
      "A *format_spec* field can also include nested replacement fields\n",
      "within it. These nested replacement fields may contain a field name,\n",
      "conversion flag and format specification, but deeper nesting is not\n",
      "allowed.  The replacement fields within the format_spec are\n",
      "substituted before the *format_spec* string is interpreted. This\n",
      "allows the formatting of a value to be dynamically specified.\n",
      "\n",
      "See the Format examples section for some examples.\n",
      "\n",
      "\n",
      "Format Specification Mini-Language\n",
      "==================================\n",
      "\n",
      "“Format specifications” are used within replacement fields contained\n",
      "within a format string to define how individual values are presented\n",
      "(see Format String Syntax and Formatted string literals). They can\n",
      "also be passed directly to the built-in \"format()\" function.  Each\n",
      "formattable type may define how the format specification is to be\n",
      "interpreted.\n",
      "\n",
      "Most built-in types implement the following options for format\n",
      "specifications, although some of the formatting options are only\n",
      "supported by the numeric types.\n",
      "\n",
      "A general convention is that an empty format string (\"\"\"\") produces\n",
      "the same result as if you had called \"str()\" on the value. A non-empty\n",
      "format string typically modifies the result.\n",
      "\n",
      "The general form of a *standard format specifier* is:\n",
      "\n",
      "   format_spec     ::= [[fill]align][sign][#][0][width][grouping_option][.precision][type]\n",
      "   fill            ::= <any character>\n",
      "   align           ::= \"<\" | \">\" | \"=\" | \"^\"\n",
      "   sign            ::= \"+\" | \"-\" | \" \"\n",
      "   width           ::= digit+\n",
      "   grouping_option ::= \"_\" | \",\"\n",
      "   precision       ::= digit+\n",
      "   type            ::= \"b\" | \"c\" | \"d\" | \"e\" | \"E\" | \"f\" | \"F\" | \"g\" | \"G\" | \"n\" | \"o\" | \"s\" | \"x\" | \"X\" | \"%\"\n",
      "\n",
      "If a valid *align* value is specified, it can be preceded by a *fill*\n",
      "character that can be any character and defaults to a space if\n",
      "omitted. It is not possible to use a literal curly brace (“\"{\"” or\n",
      "“\"}\"”) as the *fill* character in a formatted string literal or when\n",
      "using the \"str.format()\" method.  However, it is possible to insert a\n",
      "curly brace with a nested replacement field.  This limitation doesn’t\n",
      "affect the \"format()\" function.\n",
      "\n",
      "The meaning of the various alignment options is as follows:\n",
      "\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | Option    | Meaning                                                    |\n",
      "   |===========|============================================================|\n",
      "   | \"'<'\"     | Forces the field to be left-aligned within the available   |\n",
      "   |           | space (this is the default for most objects).              |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'>'\"     | Forces the field to be right-aligned within the available  |\n",
      "   |           | space (this is the default for numbers).                   |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'='\"     | Forces the padding to be placed after the sign (if any)    |\n",
      "   |           | but before the digits.  This is used for printing fields   |\n",
      "   |           | in the form ‘+000000120’. This alignment option is only    |\n",
      "   |           | valid for numeric types.  It becomes the default when ‘0’  |\n",
      "   |           | immediately precedes the field width.                      |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'^'\"     | Forces the field to be centered within the available       |\n",
      "   |           | space.                                                     |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "\n",
      "Note that unless a minimum field width is defined, the field width\n",
      "will always be the same size as the data to fill it, so that the\n",
      "alignment option has no meaning in this case.\n",
      "\n",
      "The *sign* option is only valid for number types, and can be one of\n",
      "the following:\n",
      "\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | Option    | Meaning                                                    |\n",
      "   |===========|============================================================|\n",
      "   | \"'+'\"     | indicates that a sign should be used for both positive as  |\n",
      "   |           | well as negative numbers.                                  |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'-'\"     | indicates that a sign should be used only for negative     |\n",
      "   |           | numbers (this is the default behavior).                    |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | space     | indicates that a leading space should be used on positive  |\n",
      "   |           | numbers, and a minus sign on negative numbers.             |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "\n",
      "The \"'#'\" option causes the “alternate form” to be used for the\n",
      "conversion.  The alternate form is defined differently for different\n",
      "types.  This option is only valid for integer, float, complex and\n",
      "Decimal types. For integers, when binary, octal, or hexadecimal output\n",
      "is used, this option adds the prefix respective \"'0b'\", \"'0o'\", or\n",
      "\"'0x'\" to the output value. For floats, complex and Decimal the\n",
      "alternate form causes the result of the conversion to always contain a\n",
      "decimal-point character, even if no digits follow it. Normally, a\n",
      "decimal-point character appears in the result of these conversions\n",
      "only if a digit follows it. In addition, for \"'g'\" and \"'G'\"\n",
      "conversions, trailing zeros are not removed from the result.\n",
      "\n",
      "The \"','\" option signals the use of a comma for a thousands separator.\n",
      "For a locale aware separator, use the \"'n'\" integer presentation type\n",
      "instead.\n",
      "\n",
      "Changed in version 3.1: Added the \"','\" option (see also **PEP 378**).\n",
      "\n",
      "The \"'_'\" option signals the use of an underscore for a thousands\n",
      "separator for floating point presentation types and for integer\n",
      "presentation type \"'d'\".  For integer presentation types \"'b'\", \"'o'\",\n",
      "\"'x'\", and \"'X'\", underscores will be inserted every 4 digits.  For\n",
      "other presentation types, specifying this option is an error.\n",
      "\n",
      "Changed in version 3.6: Added the \"'_'\" option (see also **PEP 515**).\n",
      "\n",
      "*width* is a decimal integer defining the minimum total field width,\n",
      "including any prefixes, separators, and other formatting characters.\n",
      "If not specified, then the field width will be determined by the\n",
      "content.\n",
      "\n",
      "When no explicit alignment is given, preceding the *width* field by a\n",
      "zero (\"'0'\") character enables sign-aware zero-padding for numeric\n",
      "types.  This is equivalent to a *fill* character of \"'0'\" with an\n",
      "*alignment* type of \"'='\".\n",
      "\n",
      "The *precision* is a decimal number indicating how many digits should\n",
      "be displayed after the decimal point for a floating point value\n",
      "formatted with \"'f'\" and \"'F'\", or before and after the decimal point\n",
      "for a floating point value formatted with \"'g'\" or \"'G'\".  For non-\n",
      "number types the field indicates the maximum field size - in other\n",
      "words, how many characters will be used from the field content. The\n",
      "*precision* is not allowed for integer values.\n",
      "\n",
      "Finally, the *type* determines how the data should be presented.\n",
      "\n",
      "The available string presentation types are:\n",
      "\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | Type      | Meaning                                                    |\n",
      "   |===========|============================================================|\n",
      "   | \"'s'\"     | String format. This is the default type for strings and    |\n",
      "   |           | may be omitted.                                            |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | None      | The same as \"'s'\".                                         |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "\n",
      "The available integer presentation types are:\n",
      "\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | Type      | Meaning                                                    |\n",
      "   |===========|============================================================|\n",
      "   | \"'b'\"     | Binary format. Outputs the number in base 2.               |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'c'\"     | Character. Converts the integer to the corresponding       |\n",
      "   |           | unicode character before printing.                         |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'d'\"     | Decimal Integer. Outputs the number in base 10.            |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'o'\"     | Octal format. Outputs the number in base 8.                |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'x'\"     | Hex format. Outputs the number in base 16, using lower-    |\n",
      "   |           | case letters for the digits above 9.                       |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'X'\"     | Hex format. Outputs the number in base 16, using upper-    |\n",
      "   |           | case letters for the digits above 9.                       |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'n'\"     | Number. This is the same as \"'d'\", except that it uses the |\n",
      "   |           | current locale setting to insert the appropriate number    |\n",
      "   |           | separator characters.                                      |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | None      | The same as \"'d'\".                                         |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "\n",
      "In addition to the above presentation types, integers can be formatted\n",
      "with the floating point presentation types listed below (except \"'n'\"\n",
      "and \"None\"). When doing so, \"float()\" is used to convert the integer\n",
      "to a floating point number before formatting.\n",
      "\n",
      "The available presentation types for floating point and decimal values\n",
      "are:\n",
      "\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | Type      | Meaning                                                    |\n",
      "   |===========|============================================================|\n",
      "   | \"'e'\"     | Exponent notation. Prints the number in scientific         |\n",
      "   |           | notation using the letter ‘e’ to indicate the exponent.    |\n",
      "   |           | The default precision is \"6\".                              |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'E'\"     | Exponent notation. Same as \"'e'\" except it uses an upper   |\n",
      "   |           | case ‘E’ as the separator character.                       |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'f'\"     | Fixed-point notation. Displays the number as a fixed-point |\n",
      "   |           | number. The default precision is \"6\".                      |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'F'\"     | Fixed-point notation. Same as \"'f'\", but converts \"nan\" to |\n",
      "   |           | \"NAN\" and \"inf\" to \"INF\".                                  |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'g'\"     | General format.  For a given precision \"p >= 1\", this      |\n",
      "   |           | rounds the number to \"p\" significant digits and then       |\n",
      "   |           | formats the result in either fixed-point format or in      |\n",
      "   |           | scientific notation, depending on its magnitude.  The      |\n",
      "   |           | precise rules are as follows: suppose that the result      |\n",
      "   |           | formatted with presentation type \"'e'\" and precision \"p-1\" |\n",
      "   |           | would have exponent \"exp\".  Then, if \"m <= exp < p\", where |\n",
      "   |           | \"m\" is -4 for floats and -6 for \"Decimals\", the number is  |\n",
      "   |           | formatted with presentation type \"'f'\" and precision       |\n",
      "   |           | \"p-1-exp\".  Otherwise, the number is formatted with        |\n",
      "   |           | presentation type \"'e'\" and precision \"p-1\". In both cases |\n",
      "   |           | insignificant trailing zeros are removed from the          |\n",
      "   |           | significand, and the decimal point is also removed if      |\n",
      "   |           | there are no remaining digits following it, unless the     |\n",
      "   |           | \"'#'\" option is used.  Positive and negative infinity,     |\n",
      "   |           | positive and negative zero, and nans, are formatted as     |\n",
      "   |           | \"inf\", \"-inf\", \"0\", \"-0\" and \"nan\" respectively,           |\n",
      "   |           | regardless of the precision.  A precision of \"0\" is        |\n",
      "   |           | treated as equivalent to a precision of \"1\". The default   |\n",
      "   |           | precision is \"6\".                                          |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'G'\"     | General format. Same as \"'g'\" except switches to \"'E'\" if  |\n",
      "   |           | the number gets too large. The representations of infinity |\n",
      "   |           | and NaN are uppercased, too.                               |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'n'\"     | Number. This is the same as \"'g'\", except that it uses the |\n",
      "   |           | current locale setting to insert the appropriate number    |\n",
      "   |           | separator characters.                                      |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | \"'%'\"     | Percentage. Multiplies the number by 100 and displays in   |\n",
      "   |           | fixed (\"'f'\") format, followed by a percent sign.          |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "   | None      | Similar to \"'g'\", except that fixed-point notation, when   |\n",
      "   |           | used, has at least one digit past the decimal point. The   |\n",
      "   |           | default precision is as high as needed to represent the    |\n",
      "   |           | particular value. The overall effect is to match the       |\n",
      "   |           | output of \"str()\" as altered by the other format           |\n",
      "   |           | modifiers.                                                 |\n",
      "   +-----------+------------------------------------------------------------+\n",
      "\n",
      "\n",
      "Format examples\n",
      "===============\n",
      "\n",
      "This section contains examples of the \"str.format()\" syntax and\n",
      "comparison with the old \"%\"-formatting.\n",
      "\n",
      "In most of the cases the syntax is similar to the old \"%\"-formatting,\n",
      "with the addition of the \"{}\" and with \":\" used instead of \"%\". For\n",
      "example, \"'%03.2f'\" can be translated to \"'{:03.2f}'\".\n",
      "\n",
      "The new format syntax also supports new and different options, shown\n",
      "in the following examples.\n",
      "\n",
      "Accessing arguments by position:\n",
      "\n",
      "   >>> '{0}, {1}, {2}'.format('a', 'b', 'c')\n",
      "   'a, b, c'\n",
      "   >>> '{}, {}, {}'.format('a', 'b', 'c')  # 3.1+ only\n",
      "   'a, b, c'\n",
      "   >>> '{2}, {1}, {0}'.format('a', 'b', 'c')\n",
      "   'c, b, a'\n",
      "   >>> '{2}, {1}, {0}'.format(*'abc')      # unpacking argument sequence\n",
      "   'c, b, a'\n",
      "   >>> '{0}{1}{0}'.format('abra', 'cad')   # arguments' indices can be repeated\n",
      "   'abracadabra'\n",
      "\n",
      "Accessing arguments by name:\n",
      "\n",
      "   >>> 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')\n",
      "   'Coordinates: 37.24N, -115.81W'\n",
      "   >>> coord = {'latitude': '37.24N', 'longitude': '-115.81W'}\n",
      "   >>> 'Coordinates: {latitude}, {longitude}'.format(**coord)\n",
      "   'Coordinates: 37.24N, -115.81W'\n",
      "\n",
      "Accessing arguments’ attributes:\n",
      "\n",
      "   >>> c = 3-5j\n",
      "   >>> ('The complex number {0} is formed from the real part {0.real} '\n",
      "   ...  'and the imaginary part {0.imag}.').format(c)\n",
      "   'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.'\n",
      "   >>> class Point:\n",
      "   ...     def __init__(self, x, y):\n",
      "   ...         self.x, self.y = x, y\n",
      "   ...     def __str__(self):\n",
      "   ...         return 'Point({self.x}, {self.y})'.format(self=self)\n",
      "   ...\n",
      "   >>> str(Point(4, 2))\n",
      "   'Point(4, 2)'\n",
      "\n",
      "Accessing arguments’ items:\n",
      "\n",
      "   >>> coord = (3, 5)\n",
      "   >>> 'X: {0[0]};  Y: {0[1]}'.format(coord)\n",
      "   'X: 3;  Y: 5'\n",
      "\n",
      "Replacing \"%s\" and \"%r\":\n",
      "\n",
      "   >>> \"repr() shows quotes: {!r}; str() doesn't: {!s}\".format('test1', 'test2')\n",
      "   \"repr() shows quotes: 'test1'; str() doesn't: test2\"\n",
      "\n",
      "Aligning the text and specifying a width:\n",
      "\n",
      "   >>> '{:<30}'.format('left aligned')\n",
      "   'left aligned                  '\n",
      "   >>> '{:>30}'.format('right aligned')\n",
      "   '                 right aligned'\n",
      "   >>> '{:^30}'.format('centered')\n",
      "   '           centered           '\n",
      "   >>> '{:*^30}'.format('centered')  # use '*' as a fill char\n",
      "   '***********centered***********'\n",
      "\n",
      "Replacing \"%+f\", \"%-f\", and \"% f\" and specifying a sign:\n",
      "\n",
      "   >>> '{:+f}; {:+f}'.format(3.14, -3.14)  # show it always\n",
      "   '+3.140000; -3.140000'\n",
      "   >>> '{: f}; {: f}'.format(3.14, -3.14)  # show a space for positive numbers\n",
      "   ' 3.140000; -3.140000'\n",
      "   >>> '{:-f}; {:-f}'.format(3.14, -3.14)  # show only the minus -- same as '{:f}; {:f}'\n",
      "   '3.140000; -3.140000'\n",
      "\n",
      "Replacing \"%x\" and \"%o\" and converting the value to different bases:\n",
      "\n",
      "   >>> # format also supports binary numbers\n",
      "   >>> \"int: {0:d};  hex: {0:x};  oct: {0:o};  bin: {0:b}\".format(42)\n",
      "   'int: 42;  hex: 2a;  oct: 52;  bin: 101010'\n",
      "   >>> # with 0x, 0o, or 0b as prefix:\n",
      "   >>> \"int: {0:d};  hex: {0:#x};  oct: {0:#o};  bin: {0:#b}\".format(42)\n",
      "   'int: 42;  hex: 0x2a;  oct: 0o52;  bin: 0b101010'\n",
      "\n",
      "Using the comma as a thousands separator:\n",
      "\n",
      "   >>> '{:,}'.format(1234567890)\n",
      "   '1,234,567,890'\n",
      "\n",
      "Expressing a percentage:\n",
      "\n",
      "   >>> points = 19\n",
      "   >>> total = 22\n",
      "   >>> 'Correct answers: {:.2%}'.format(points/total)\n",
      "   'Correct answers: 86.36%'\n",
      "\n",
      "Using type-specific formatting:\n",
      "\n",
      "   >>> import datetime\n",
      "   >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n",
      "   >>> '{:%Y-%m-%d %H:%M:%S}'.format(d)\n",
      "   '2010-07-04 12:15:58'\n",
      "\n",
      "Nesting arguments and more complex examples:\n",
      "\n",
      "   >>> for align, text in zip('<^>', ['left', 'center', 'right']):\n",
      "   ...     '{0:{fill}{align}16}'.format(text, fill=align, align=align)\n",
      "   ...\n",
      "   'left<<<<<<<<<<<<'\n",
      "   '^^^^^center^^^^^'\n",
      "   '>>>>>>>>>>>right'\n",
      "   >>>\n",
      "   >>> octets = [192, 168, 0, 1]\n",
      "   >>> '{:02X}{:02X}{:02X}{:02X}'.format(*octets)\n",
      "   'C0A80001'\n",
      "   >>> int(_, 16)\n",
      "   3232235521\n",
      "   >>>\n",
      "   >>> width = 5\n",
      "   >>> for num in range(5,12): \n",
      "   ...     for base in 'dXob':\n",
      "   ...         print('{0:{width}{base}}'.format(num, base=base, width=width), end=' ')\n",
      "   ...     print()\n",
      "   ...\n",
      "       5     5     5   101\n",
      "       6     6     6   110\n",
      "       7     7     7   111\n",
      "       8     8    10  1000\n",
      "       9     9    11  1001\n",
      "      10     A    12  1010\n",
      "      11     B    13  1011\n",
      "\n",
      "Related help topics: OPERATORS\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help('FORMATTING')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my_var     = 1.23\n"
     ]
    }
   ],
   "source": [
    "formatted = '{:<10} = {:.2f}'.format(key, value)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "{:.2f}는 format(value, '.2f') 와 같음"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "특별 메서드인 \\__format\\__을 사용해 클래스별로 형식화 방식을 커스텀 가능"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**이스케이프**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12.50%\n",
      "1.23 replaces {}\n"
     ]
    }
   ],
   "source": [
    "print('%.2f%%' % 12.5)\n",
    "print('{} replaces {{}}'.format(1.23))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "위치 지정자 중괄호에 위치 인덱스를 전달 할 수 있음."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.234 = my_var\n"
     ]
    }
   ],
   "source": [
    "formatted = '{1} = {0}'.format(key, value)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "세 번째 문제점도 간단히 해결 가능"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "철수는 음식을 좋아해. 철수가 요리하는 모습을 봐요.\n"
     ]
    }
   ],
   "source": [
    "name = '철수'\n",
    "formatted = '{0}는 음식을 좋아해. {0}가 요리하는 모습을 봐요.'.format(name)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "두번째는 역시 해결하지 못함"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i, (item, count) in enumerate(pantry):\n",
    "    old_style = '#%d: %-10s = %d' % (\n",
    "        i + 1,\n",
    "        item.title(),\n",
    "        round(count))\n",
    "        \n",
    "    new_style = '#{}: {:<10s} = {}'.format(\n",
    "        i + 1,\n",
    "        item.title(),\n",
    "        round(count))\n",
    "        \n",
    "    assert old_style == new_style"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "str.format과 함께 사용하는 형식 지정자에는 딕셔너리 키나 리스트 인덱스를 조합해 위치 지정자에 사용하거나 값을 유니코드나 repr 문자열로 변화나는 등의 고급 옵션이 있다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "첫번째 글자는 't'\n"
     ]
    }
   ],
   "source": [
    "formatted = '첫번째 글자는 {menu[oyster][0]!r}'.format(\n",
    "    menu=menu)\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "이 기능도 네 번째 문제점인 키가 반복되는 경우의 중복을 줄여주지는 못함"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "old_template = (\n",
    "    'Today\\'s soup is %(soup)s, '\n",
    "    'buy one get two %(oyster)s oysters, '\n",
    "    'and our special entrée is %(special)s.')\n",
    "old_formatted = template % {\n",
    "    'soup': 'lentil',\n",
    "    'oyster': 'tongyoung',\n",
    "    'special': 'schnitzel',\n",
    "}\n",
    "\n",
    "new_template = (\n",
    "    'Today\\'s soup is {soup}, '\n",
    "    'buy one get two {oyster} oysters, '\n",
    "    'and our special entrée is {special}.')\n",
    "new_formatted = new_template.format(\n",
    "    soup='lentil',\n",
    "    oyster='tongyoung',\n",
    "    special='schnitzel',\n",
    ")\n",
    "\n",
    "assert old_formatted == new_formatted"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 인터폴레이션을 통한 형식 문자열"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "이 문제를 한 번에 완전히 해결하기 위해 파이썬 3.6부터는 인터폴레이션을 통한 형식 문자열(**f-문자열**)이 도입됨"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "my_var = 1.234\n"
     ]
    }
   ],
   "source": [
    "key = 'my_var'\n",
    "value = 1.234\n",
    "\n",
    "formatted = f'{key} = {value}'\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'my_var'   = 1.23\n"
     ]
    }
   ],
   "source": [
    "formatted = f'{key!r:<10} = {value:.2f}'\n",
    "print(formatted)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "다른 포매팅 방식에 비해 짧다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_string = f'{key:<10} = {value:.2f}'\n",
    "\n",
    "c_tuple  = '%-10s = %.2f' % (key, value)\n",
    "\n",
    "str_args = '{:<10} = {:.2f}'.format(key, value)\n",
    "\n",
    "str_kw   = '{key:<10} = {value:.2f}'.format(key=key,\n",
    "                                            value=value)\n",
    "\n",
    "c_dict   = '%(key)-10s = %(value).2f' % {'key': key,\n",
    "                                         'value': value}\n",
    "\n",
    "assert c_tuple == c_dict == f_string\n",
    "assert str_args == str_kw == f_string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "f-문자열을 사용하면 위치 지정자 중괄호 안에 완전한 파이썬 식을 넣을 수 있다.\n",
    "\n",
    "두 번째 문제점을 해결한다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i, (item, count) in enumerate(pantry):\n",
    "    old_style = '#%d: %-10s = %d' % (\n",
    "        i + 1,\n",
    "        item.title(),\n",
    "        round(count))\n",
    "        \n",
    "    new_style = '#{}: {:<10s} = {}'.format(\n",
    "        i + 1,\n",
    "        item.title(),\n",
    "        round(count))\n",
    "        \n",
    "    f_string = f'#{i+1}: {item.title():<10s} = {round(count)}'\n",
    "        \n",
    "    assert old_style == new_style == f_string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "f-문자열을 여러 줄로 나눌 수도 있다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#1: 아보카도       = 1\n",
      "#2: 바나나        = 2\n",
      "#3: 체리         = 15\n"
     ]
    }
   ],
   "source": [
    "for i, (item, count) in enumerate(pantry):\n",
    "    print(f'#{i+1}: '\n",
    "    f'{item.title():<10s} = '\n",
    "    f'{round(count)}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "파이썬 식을 형식 지정자 옵션에 넣을 수도 있다."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "내가 고른 숫자는 1.235\n"
     ]
    }
   ],
   "source": [
    "places = 3\n",
    "number = 1.23456\n",
    "print(f'내가 고른 숫자는 {number:.{places}f}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**결론 : f-문자열을 쓰자**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- % 연산자를 사용하는 C 스타일 형식화 문자열은 여러 가지 단점과 번잡성이라는 문제가 있다.\n",
    "- str.format 메서드는 형식 지정자 미니 언어에서 유용한 개념 몇 가지를 새로 제공했다. 하지만 이를 제외하면 str.format 메서드도 C 스타일 형식 문자열의 문제점을 그대로 가지고 있으므로, 가능하면 str.format 사용을 피해야 한다.\n",
    "- f-문자열은 값을 문자열 안에 넣는 새로운 구문으로, C 스타일 형식화 문자열의 가장 큰 문제점을 해결해준다.\n",
    "- f-문자열은 간결하지만, 위치 지정자 안에 임의의 파이썬 식을 직접 포함시킬 수 있으므로 매우 강력하다."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}