{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "#Section3.파이썬 기초 사용법"
      ],
      "metadata": {
        "id": "B5Eev1_JLwLj"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 3. 변수와 데이터형의 기본 사용법\n",
        "#### 변수의 사용\n"
      ],
      "metadata": {
        "id": "aobS6Y1iF747"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "다음은 변수 이름을 잘못 사용한 예다. 실행 결과가 SyntaxError로 나와 철자 오류처럼 보이지만\n",
        "def라는 파이썬 예약어를 사용해 발생한 오류다."
      ],
      "metadata": {
        "id": "z_aYTKH4GDBo"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 137
        },
        "id": "Y6jeDB1AFkHt",
        "outputId": "31409fa6-7e17-4428-c8e7-15904025e958"
      },
      "outputs": [
        {
          "output_type": "error",
          "ename": "SyntaxError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-1-30e07b63f637>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    def=5\u001b[0m\n\u001b[0m       ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
          ]
        }
      ],
      "source": [
        "def=5\n",
        "print(def)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "#### ❶ 하나의 변수에 값 할당"
      ],
      "metadata": {
        "id": "kZQ6Bc4PGOPT"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "stock_price=85000\n",
        "stock_price"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Gvce93qIGSY_",
        "outputId": "eacf6cfe-f252-4c72-e5ac-6d441afa5c78"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "85000"
            ]
          },
          "metadata": {},
          "execution_count": 2
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "#### ❷ 동시에 여러 변수에 값 할당"
      ],
      "metadata": {
        "id": "6OhcZfAOGVzC"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "ss, lg, sk=80000, 140000, 200000\n",
        "print(\"ss: %d\" % ss)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "pjaIFBzeGZDP",
        "outputId": "c0eaaf86-839f-4d19-d5f8-7e498acc11ea"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "ss: 80000\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 숫자형과 문자형의 기본 사용"
      ],
      "metadata": {
        "id": "jDFi8783Gcu6"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "amount=100000\n",
        "amount"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "SWFnM82uGfKi",
        "outputId": "cb423eb3-0881-481e-8678-204bf0087468"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "100000"
            ]
          },
          "metadata": {},
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "quantity=15\n",
        "price=amount/quantity\n",
        "price "
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "N1dN-8xQGhoH",
        "outputId": "bb1436b4-8660-4734-877c-fa0b8eea61ce"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "6666.666666666667"
            ]
          },
          "metadata": {},
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "stock_price=\"85000\"\n",
        "print(stock_price)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "V4lM-lbdGk2p",
        "outputId": "ea0bdfc1-6279-4585-b155-d54b08f3e4c1"
      },
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "85000\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "string1=\"사느냐, 죽느냐? 그것이 문제다.\\n\"\n",
        "string2='어떤 것이 더 고귀한 것일까?\\n'\n",
        "string3= \"\"\"Whether 'tis nobler in the mind to suffer\n",
        "the slings and arrows of outrageous fortune,\n",
        "가혹한 운명의 돌팔매와 화살을 견디는 것이 더 고귀한 것일까?\\n\"\"\"\n",
        "string4='''Or to take arms against a sea of troubles,\n",
        "And, by opposing, end them?\n",
        "아니면 고통의 바다에 맞서\n",
        "무기를 들고 싸워 그 고통을 끝내는 것이 더 고귀한 것일까?'''\n",
        "print(string1, string2, string3, string4)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "0csrr9UVGnr1",
        "outputId": "b7834167-1322-4d83-f3ce-1165d00d8365"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "사느냐, 죽느냐? 그것이 문제다.\n",
            " 어떤 것이 더 고귀한 것일까?\n",
            " Whether 'tis nobler in the mind to suffer\n",
            "the slings and arrows of outrageous fortune,\n",
            "가혹한 운명의 돌팔매와 화살을 견디는 것이 더 고귀한 것일까?\n",
            " Or to take arms against a sea of troubles,\n",
            "And, by opposing, end them?\n",
            "아니면 고통의 바다에 맞서\n",
            "무기를 들고 싸워 그 고통을 끝내는 것이 더 고귀한 것일까?\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 데이터형의 확인"
      ],
      "metadata": {
        "id": "U5PNxJF1GsL7"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "stock_price=85000\n",
        "apple_stock_price=128.5\n",
        "print(stock_price, type(stock_price))\n",
        "print(apple_stock_price, type(apple_stock_price))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "I1cS_irbGumq",
        "outputId": "989e9485-4c90-4f26-8226-0d79d3d8f012"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "85000 <class 'int'>\n",
            "128.5 <class 'float'>\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 4. 숫자형 연산"
      ],
      "metadata": {
        "id": "5eBLwYfmG7y-"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "stock_price=85000\n",
        "quantity=10\n",
        "amount= stock_price*quantity\n",
        "fee_rate= 0.01\n",
        "total_fee=amount*fee_rate\n",
        "print(amount, type(amount))\n",
        "print(total_fee, type(total_fee))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "IMqDN6FgG-Vu",
        "outputId": "90f5c78e-3d5b-436c-8fb3-0f46e350bcc3"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "850000 <class 'int'>\n",
            "8500.0 <class 'float'>\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "a=1\n",
        "b=2\n",
        "c, d, e=3, 4, 5\n",
        "print(a+b, a-b, a*b, a/b)\n",
        "print(c**b, b**0.5)\n",
        "print(e/b, e//b, e%b) "
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "jonNwf6OHBK5",
        "outputId": "0c25a303-c706-4624-e015-274c3b3ec6e2"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "3 -1 2 0.5\n",
            "9 1.4142135623730951\n",
            "2.5 2 1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 5. 숫자형 포매팅"
      ],
      "metadata": {
        "id": "hG4cdgDQHEfa"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "c, d=3, 4\n",
        "e=c+d\n",
        "print(\"c+d의 값은: e=c+d={0:d}\".format(e))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "eUSSFyG6HHaw",
        "outputId": "36c65628-fe56-426e-ea56-d6af090d23a6"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "c+d의 값은: e=c+d=7\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "a=1\n",
        "b=2\n",
        "c, d, e=3, 4, 5\n",
        "print(\"사칙연산 결과는: {0}, {1}, {2}, {3}\".format(a+b, a-b, a*b, a/b))\n",
        "print(\"c의 e 제곱과 b의 제곱근 결과는: {0:d}, {1:.2f}\".format(c**e, b**0.5))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "fTQko46bHKAj",
        "outputId": "e0fccd4f-5d66-4115-a135-60c770b3bd6b"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "사칙연산 결과는: 3, -1, 2, 0.5\n",
            "c의 e 제곱과 b의 제곱근 결과는: 243, 1.41\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 6. 문자열 연산\n",
        "### 문자열 연결"
      ],
      "metadata": {
        "id": "ANC8QaJDHMX6"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "price=\"85,000\"\n",
        "stock_price=company_name + \" \" + price +\" \" # 문자열 연결하기\n",
        "print(\"*\"*50) # * 문자를 50번 출력하기\n",
        "print(stock_price*3) # stock_price 문자열을 3번 출력하기"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "uRDDwSfEHRIf",
        "outputId": "858e3688-1c76-49b1-f583-6070debd74f9"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "**************************************************\n",
            "Samsung 85,000 Samsung 85,000 Samsung 85,000 \n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "###문자열 인덱싱"
      ],
      "metadata": {
        "id": "nwMrhpNBHWmj"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "variable='Hello Python'\n",
        "print(variable)\n",
        "print(variable[0], variable[-1],\n",
        "variable[1])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "-ToJnKOQHZMs",
        "outputId": "e64f767b-b7eb-4236-b7d6-8d58056fc39d"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Hello Python\n",
            "H n e\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "###문자열 슬라이싱"
      ],
      "metadata": {
        "id": "tbJdpwKQHbVq"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string='To be, or not to be, that is the question'\n",
        "print(len(single_string), single_string[0], single_string[:3], single_string[35:-1])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "W2uxUcFMHeR8",
        "outputId": "5e51be47-0d0e-4fcd-ee5d-5d101710992c"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "41 T To  estio\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 7. 문자열 포매팅\n",
        "### 서식 문자를 이용한 포매팅"
      ],
      "metadata": {
        "id": "IZDtS3EnHgzY"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "quantity=5\n",
        "\"I have %d stocks.\" % quantity"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "gC8bvwBrHlDq",
        "outputId": "98f32ae7-51bb-4b8f-924b-c95b4f8be8c6"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'I have 5 stocks.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "\"I have %s stocks.\" %company_name"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "lm0PLTY1HooB",
        "outputId": "c03e1b66-fa54-4914-b5b7-ced1d8b054d5"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'I have Samsung stocks.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "quantity=5\n",
        "\"I have %d %s stocks.\" %(quantity, company_name)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "b1r9VyARHwzA",
        "outputId": "db49bbff-b7ff-4619-959e-ea70d7f49b78"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'I have 5 Samsung stocks.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### format 함수를 이용한 포매팅"
      ],
      "metadata": {
        "id": "G_y7Xz4PHtL_"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "price=\"85,000\"\n",
        "stock_price=\"{0} {1}\".format(company_name, price)\n",
        "stock_price"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "NbId5-sKH1KQ",
        "outputId": "b2452fad-7001-43de-d9e9-fb94468a8dbe"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Samsung 85,000'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "price=\"85,000\"\n",
        "stock_price=\"{0} {price}\".format(company_name,price=50000)\n",
        "stock_price"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "EJfvSEhOH3Kg",
        "outputId": "219073ba-5742-4642-f043-eb32472e5e40"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Samsung 50000'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### f 문자열 포매팅"
      ],
      "metadata": {
        "id": "1nqc1bMEH6bH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "price=\"85,000\"\n",
        "stock_price=f\"{company_name} {price}\"\n",
        "stock_price"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "mPzo9-fLH9Qg",
        "outputId": "6243ac63-fc78-45bf-f44d-d94eb9b1bd52"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Samsung 85,000'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "price=\"85,000\"\n",
        "new_price=\"100,000\"\n",
        "stock_price=f\"\"\"{company_name}\n",
        "{price}\n",
        "{new_price}\"\"\"\n",
        "print(stock_price)\n",
        "stock_price"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 90
        },
        "id": "nNdBbfUNIBS4",
        "outputId": "5b24c59a-d717-41fc-aac1-c37f9fb16a90"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Samsung\n",
            "85,000\n",
            "100,000\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Samsung\\n85,000\\n100,000'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "##8. 문자열 내장 함수"
      ],
      "metadata": {
        "id": "McfdB_7AIEEK"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 문자 개수 세기: count 함수"
      ],
      "metadata": {
        "id": "gv5vU1RoIGyH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"To be, or not to be, that is the question\"\n",
        "single_string.count(\"t\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "jRCzmnTLIJLB",
        "outputId": "b03e0838-e01d-4438-95ed-e9de87ca581b"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "6"
            ]
          },
          "metadata": {},
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 문자 위치 찾기: find 함수"
      ],
      "metadata": {
        "id": "K3gFVt7pILce"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"To be, or not to be, that is the question\"\n",
        "single_string.find('t')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "48gwLsWdIOJQ",
        "outputId": "6350a91e-9169-43fb-82c5-6aeb2a4cf108"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "12"
            ]
          },
          "metadata": {},
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "###첫 글자만 대문자로 바꾸기: capitalize 함수"
      ],
      "metadata": {
        "id": "HxWYa1zzIQhO"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"to be, or not to be, that is the question\"\n",
        "text=single_string\n",
        "text.capitalize( )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "IDfopnBvITAi",
        "outputId": "f2ac13d1-f129-42a0-a7ab-c72246eb485d"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'To be, or not to be, that is the question'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "###모든 문자를 대문자/소문자로 바꾸기: upper 함수, lower 함수"
      ],
      "metadata": {
        "id": "6Slp_CamIXWe"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"To be, or not to be, that is the question\"\n",
        "text=single_string\n",
        "text.upper( ) # text 변수값을 대문자로 출력한다."
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "3PBTm-KLIZc0",
        "outputId": "29bd2857-2b74-4751-d934-27887b1ec5f0"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'TO BE, OR NOT TO BE, THAT IS THE QUESTION'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 27
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 특정 문자 바꾸기: replace 함수"
      ],
      "metadata": {
        "id": "qTx76OYPIbgo"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"To be, or not to be, that is the question\"\n",
        "text=single_string\n",
        "text.replace(\"question\",\"QUESTION\") # text 변수값 일부를 대문자로 출력한다."
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "fBHsdfJUIeND",
        "outputId": "79cd6f76-a7d0-443f-fda7-22bd146a9556"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'To be, or not to be, that is the QUESTION'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 단어 단위로 쪼개기: split 함수"
      ],
      "metadata": {
        "id": "VLF2kE-LIf7y"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"To be, or not to be, that is the question\"\n",
        "text=single_string\n",
        "text.split( ) # text 변수값을 공백을 기준으로 나눈다."
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "hA3DGxP9IkdV",
        "outputId": "e4ffa398-e452-4657-a9fd-7cd9f0edf242"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['To', 'be,', 'or', 'not', 'to', 'be,', 'that', 'is', 'the', 'question']"
            ]
          },
          "metadata": {},
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### 문자열의 시작과 끝에서 주어진 문자 삭제하기: strip 함수"
      ],
      "metadata": {
        "id": "rbnnolYJInDb"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "'http://www.Python.org'.strip('http://')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "gxVIK8f4Ip17",
        "outputId": "d08aa579-c7d1-453a-da95-a67be2027721"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'www.Python.org'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 30
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "' Welcome to Hanbit.co.kr '.strip( )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "-M8fl3N5Is9F",
        "outputId": "5e39b16d-ac12-437c-dce6-0334554eb3f1"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Welcome to Hanbit.co.kr'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 31
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## 연습문제"
      ],
      "metadata": {
        "id": "LyPPTWJ2Iyge"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "variable='Hello Python'\n",
        "print(variable[0], variable[-1], variable[1])"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "GV_GYo3iI0iD",
        "outputId": "ce382dd0-cd81-4b29-e1e1-5ea32e428a29"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "H n e\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "company_name=\"Samsung\"\n",
        "\"I have %s stocks.\" %company_name"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "hZfvsiXDI2rt",
        "outputId": "f2576c50-7221-405e-ef10-98876c9ac0e1"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'I have Samsung stocks.'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 33
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "single_string=\"To be, or not to be, that is the question\"\n",
        "text=single_string\n",
        "text.replace(\"question\",\"QUESTION\")"
      ],
      "metadata": {
        "id": "klE5iZ5mI7Eh",
        "outputId": "8a98bbf4-7791-49e1-80d2-8755934774c2",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'To be, or not to be, that is the QUESTION'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 34
        }
      ]
    }
  ]
}