{ "cells": [ { "cell_type": "markdown", "id": "handed-casino", "metadata": { "deletable": false, "editable": false }, "source": [ "# Python 的資料型別\n", "\n", "> 不同應用場景的基礎資料型別。\n", "\n", "[數據交點](https://www.datainpoint.com) | 郭耀仁 \n", "\n", "## 自行定義函數的方式\n", "\n", "在 [Python 的函數使用方式](https://medium.com/datainpoint/using-functions-in-python-1b66711379aa)我們得知,函數的來源包含內建函數總共有四個管道可以取得:\n", "\n", "1. 內建函數。\n", "2. 標準模組。\n", "3. 第三方模組。\n", "4. 自行定義。\n", "\n", "這四個管道之中,僅有內建函數可以供我們直接使用,另外三個管道的函數都必須在呼叫之前確定好在欲產生作用的範疇中已經被載入或者定義。取用標準模組以及第三方模組中的函數之前,必須確認模組是否已經安裝、是否已經載入,取用自行定義的函數之前,則是必須確認該函數是否已經完成定義,自行定義函數需要考慮五個組成要件:\n", "\n", "1. 函數名稱 `function_name`。\n", "2. 輸入 `INPUTS`。\n", "3. 參數 `PARAMETERS`。\n", "4. 函數主體(縮排的程式區塊)。\n", "5. 輸出 `return` 以及 `OUTPUTS`。\n", "\n", "```\n", "def function_name(INPUTS, PARAMETERS):\n", " # body of the function\n", " # ...sequence of statements\n", " # ...\n", " return OUTPUTS\n", "``` \n", "\n", "五個組成要件看似抽象,不過想想平日購買珍珠鮮奶茶的流程,就跟函數的組成一般:\n", "\n", "1. 函數名稱:購買珍珠鮮奶茶。\n", "2. 輸入:中杯 35 元;大杯 50 元。\n", "3. 參數:甜度(無糖、微糖、半糖、少糖、全糖)與冰塊(去冰、少冰、全冰)。\n", "4. 函數主體:點餐、貼標籤、加珍珠、加冰塊、倒茶、加鮮奶一直到封口。\n", "5. 輸出:珍珠鮮奶茶。\n", "\n", "如果將哈囉世界改寫為函數形式,每次只需要輸入函數名稱並加上小括號 `hello_world()`,就可以獲得 `\"Hello, World!\"` 這個字串為輸出。" ] }, { "cell_type": "code", "execution_count": 1, "id": "endangered-legend", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, World!\n" ] } ], "source": [ "def hello_world():\n", " return \"Hello, World!\"\n", "print(hello_world())" ] }, { "cell_type": "markdown", "id": "private-average", "metadata": { "deletable": false, "editable": false }, "source": [ "## 五種基礎資料型別\n", "\n", "由於常見對資料型別應用函數的時候,都是對已經完成宣告的物件應用,而非直接對資料型別本身應用,這是因為程式設計通常在後續還會有資料記錄與運算處理的需求,並不止於將其印出來而已。所以我們需要一個能夠將完成宣告的物件所儲存之資料型別告知使用者的內建函數 `type()`,作用是將被應用物件的資料型別回傳,我們可以進而將其印出,包含字串在內,Python 有五種基礎的資料型別提供給我們使用:\n", "\n", "1. 整數 `int`\n", "2. 浮點數 `float`\n", "3. 字串 `str`\n", "4. 布林 `bool`\n", "5. None `NoneType`" ] }, { "cell_type": "code", "execution_count": 2, "id": "blocked-values", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "an_integer = 55\n", "a_float = 66.0\n", "a_string = \"Hello, World!\"\n", "bool_true = True\n", "bool_false = False\n", "none_type = None\n", "# Print out object types\n", "print(type(an_integer))\n", "print(type(a_float))\n", "print(type(a_string))\n", "print(type(bool_true))\n", "print(type(bool_false))\n", "print(type(none_type))" ] }, { "cell_type": "markdown", "id": "immune-transition", "metadata": { "deletable": false, "editable": false }, "source": [ "函數、資料型別以及將來講到的資料結構、流程控制和類別就像是積木、樂高以及拼圖一般,在單個元件存在的當下看起來沒有什麼作用,但是透過堆疊與組裝之後,就能夠建構出讓人眼睛一亮的成品,萬丈高樓平地起雖然八股,但卻能精準地傳達由程式碼搭建出應用程式的精神。\n", "具體來說,我們需要整數與浮點數來做數值運算、需要字串來做文字表示與處理、需要布林來做流程控制。\n", "數值運算\n", "整數與浮點數能夠用來進行數值運算,能夠作用在整數與浮點數上的數值運算符號有:\n", "\n", "1. `+`、`-`、`*`、`/`:加減乘除。\n", "2. `**` :次方。\n", "3. `%` :回傳餘數。\n", "4. `//` :回傳商數。\n", "\n", "數值運算時的優先順序遵循:小括號最優先、再來是次方、接著是乘除、最後是加減的慣例,如果在數值運算時希望調整優先順序,可以使用小括號 `()` 將希望先完成運算的部分包括起來,例如將華氏氣溫換算為攝氏氣溫的運算。" ] }, { "cell_type": "code", "execution_count": 3, "id": "experimental-brunswick", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0\n", "100.0\n" ] } ], "source": [ "def fahrenheit_to_celsius(x):\n", " return (x - 32) * 5/9\n", "print(fahrenheit_to_celsius(32))\n", "print(fahrenheit_to_celsius(212))" ] }, { "cell_type": "markdown", "id": "enormous-partner", "metadata": { "deletable": false, "editable": false }, "source": [ "## 文字表示與處理\n", "\n", "字串能夠用來進行文字表示與處理,可以透過三種成對的引號將字面值包裝起來建立:\n", "\n", "1. 使用成雙的單引號 '' 包裝。\n", "2. 使用成對的雙引號 \"\" 包裝。\n", "3. 使用成對的三個雙引號 \"\"\"\"\"\" 包裝。\n", "\n", "多數的時候使用這三種不會有任何分別,但是在部分情境中,使用成雙的單引號或成對的雙引號標註文字是有差別的,像是在英文句子中經常出現的非成雙單引號 '(Apostrophe)以及用作嘲諷強調的空氣雙引號(Air-quotes),當文字中的內容有出現這些元件時如果沒有特別關注,宣告的當下就會產生錯誤。" ] }, { "cell_type": "code", "execution_count": 4, "id": "steady-microphone", "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "invalid syntax (, line 1)", "output_type": "error", "traceback": [ "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m mcd = 'I'm lovin' it'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" ] } ], "source": [ "mcd = 'I'm lovin' it'" ] }, { "cell_type": "markdown", "id": "lined-bonus", "metadata": {}, "source": [ "這時候就可以使用跳脫字元反斜線 \\、不同樣式的引號或者三個雙引號來完成宣告。" ] }, { "cell_type": "code", "execution_count": 14, "id": "smaller-formula", "metadata": {}, "outputs": [], "source": [ "mcd = 'I\\'m lovin\\' it'\n", "mcd = \"I'm lovin' it\"\n", "mcd = \"\"\"I'm lovin' it\"\"\"" ] }, { "cell_type": "markdown", "id": "decent-transparency", "metadata": {}, "source": [ "其中由成對的三個雙引號 `\"\"\"\"\"\"` 建立的文字常被直接放在自行定義函數的主體下的第一段,被稱為文件字串(Docstring),如果在自行定義函數時有擺放文件字串,將會在自行定義函數被應用 `help()` 函數查詢時印出來。" ] }, { "cell_type": "code", "execution_count": 15, "id": "structural-smith", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on function fahrenheit_to_celsius in module __main__:\n", "\n", "fahrenheit_to_celsius(x)\n", " Return the Fahrenheit degree from a Celsius degree.\n", "\n" ] } ], "source": [ "def fahrenheit_to_celsius(x):\n", " \"\"\"\n", " Return the Fahrenheit degree from a Celsius degree.\n", " \"\"\"\n", " return (x - 32) * 5/9\n", "help(fahrenheit_to_celsius)" ] }, { "cell_type": "markdown", "id": "wrapped-marsh", "metadata": {}, "source": [ "運用文字時常會使用到的技巧是以特定格式印出(Print with format),具體來說是在文字中嵌入宣告好的物件,如此文字顯示的內容將隨著物件中所儲存的值而變動,透過文字的 `format()` 方法以及 f-string 語法搭配成雙的大括號 `{}` 中指定顯示外型都可以達成特定格式印出,我們透過改寫 `hello_world()` 函數為 `hello_anyone()` 函數示範。" ] }, { "cell_type": "code", "execution_count": 16, "id": "passing-engineer", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, Luke Skywalker!\n", "Hello, Anakin Skywalker!\n" ] } ], "source": [ "def hello_anyone_format(anyone):\n", " return \"Hello, {}!\".format(anyone) # format\n", "def hello_anyone_fstring(anyone):\n", " return f\"Hello, {anyone}!\" # f-string\n", "print(hello_anyone_format(\"Luke Skywalker\"))\n", "print(hello_anyone_fstring(\"Anakin Skywalker\"))" ] }, { "cell_type": "markdown", "id": "expected-brooks", "metadata": {}, "source": [ "我自己常用的特定格式有指定小數點 n 位的浮點數格式 `:.nf`、具有千分位逗號的金額格式 `:,` 這些都可以透過字串的 `format()` 方法以及 f-string 語法達成。" ] }, { "cell_type": "code", "execution_count": 17, "id": "accessory-plaza", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "32.0 degrees celsius is equal to 0.0 degrees fahrenheit\n", "212.0 degrees celsius is equal to 100.0 degrees fahrenheit\n", "A Big Mac costs 5.65 USD in US.\n", "A Big Mac costs 6,520.00 Won in South Korea.\n" ] } ], "source": [ "def fahrenheit_to_celsius(x):\n", " msg = \"{:.1f} degrees celsius is equal to {:.1f} degrees fahrenheit\".format(x, (x - 32) * 5/9)\n", " return msg\n", "def big_mac_index(country, currency, price):\n", " msg = f\"A Big Mac costs {price:,.2f} {currency} in {country}.\"\n", " return msg\n", "print(fahrenheit_to_celsius(32))\n", "print(fahrenheit_to_celsius(212))\n", "print(big_mac_index('US', 'USD', 5.65))\n", "print(big_mac_index('South Korea', 'Won', 6520))" ] }, { "cell_type": "markdown", "id": "italian-sitting", "metadata": {}, "source": [ "其他更多的字串特定格式,可以參考:。\n", "相較於在數值上運算能夠使用七個運算符號,字串能夠搭配的運算符號僅有兩個:加號 `+` 能夠進行字串的合併、乘號 `*` 能夠進行字串的複製。" ] }, { "cell_type": "code", "execution_count": 18, "id": "third-devil", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5566\n", "556655665566\n" ] } ], "source": [ "def concatenate_strings(x, y):\n", " return x + y\n", "def duplicate_strings(x, n):\n", " return x*n\n", "print(concatenate_strings(\"55\", \"66\"))\n", "print(duplicate_strings(\"5566\", 3))" ] }, { "cell_type": "markdown", "id": "primary-twins", "metadata": {}, "source": [ "## 布林\n", "\n", "我們未來進行程式碼的流程控制或者資料篩選的時候會需要條件(Conditions)以及條件的評估結果布林 bool,布林只有 `True` 與 `False` 這兩個值。這裡特別提醒,Python 與絕大多數的程式語言相同,對於英文大小寫是敏感的(Case-sensitive),像是 `True` 能夠被識別為布林,但是 `TRUE` 或者 `true` 則會被視作物件名稱。" ] }, { "cell_type": "code", "execution_count": 19, "id": "applied-helping", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n" ] }, { "ename": "NameError", "evalue": "name 'true' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# Recognize as object names, NameError will occur\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;31m#print(type(TRUE))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;31m#print(type(false))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'true' is not defined" ] } ], "source": [ "# Recognize as booleans\n", "print(type(True))\n", "print(type(False))\n", "# Recognize as object names, NameError will occur\n", "print(type(true))\n", "#print(type(TRUE))\n", "#print(type(false))\n", "#print(type(FALSE))" ] }, { "cell_type": "markdown", "id": "amino-manhattan", "metadata": {}, "source": [ "除了直接輸入 `True` 與 `False`,我們也可以透過條件得到布林,條件可以透過兩種運算符號:關係運算符(Relational operators)以及邏輯運算符(Logical operators)建立,條件的評估結果就會是布林,其中關係運算符包含:\n", "\n", "- `==`、`!=`:等於以及不等於。\n", "- `>` 、`>=`、`<`、`<=`:大於、大於等於、小於以及小於等於。\n", "- `a in b`:`a` 是否存在於 `b` 之中。\n", "- `is None` :是否為 `None`。" ] }, { "cell_type": "code", "execution_count": 20, "id": "employed-debut", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "True\n", "False\n", "False\n", "True\n", "True\n", "True\n", "False\n", "True\n" ] } ], "source": [ "x = 55\n", "y = 66\n", "a_string = \"Hello, World!\"\n", "none_type = None\n", "# Relational operators apply to numerics and text\n", "print(x == y)\n", "print(x != y)\n", "print(x > y)\n", "print(x >= y)\n", "print(x < y)\n", "print(x <= y)\n", "print(\"H\" in a_string)\n", "print(\"I\" in a_string)\n", "print(none_type is None)" ] }, { "cell_type": "markdown", "id": "swiss-writer", "metadata": {}, "source": [ "邏輯運算符則包含:\n", "\n", "- `and`、`or`:交集與聯集。\n", "- `not`:非。" ] }, { "cell_type": "code", "execution_count": 21, "id": "recovered-breath", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "False\n", "False\n", "True\n", "True\n", "False\n", "False\n", "True\n" ] } ], "source": [ "# Logical operators apply to booleans\n", "print(True and True)\n", "print(True and False)\n", "print(False and False)\n", "print(True or True)\n", "print(True or False)\n", "print(False or False)\n", "print(not True)\n", "print(not False)" ] }, { "cell_type": "markdown", "id": "surprised-memorial", "metadata": {}, "source": [ "關係運算符與邏輯運算符的差別在於前者針對數值或者文字應用,後者則針對布林應用。\n", "\n", "## None\n", "\n", "None 是未定義值(Undefined value),未定義值與 NA 值(Not Available)或虛無值 Null 等觀念相近,在一個沒有使用 `return` 回傳輸出的自行定義函數,None 就會是該函數的預設輸出。例如我們自行定義了一個只有把 `\"Hello, World!\"` 字串印出、而沒有 `return` 的 `hello_world()` 函數。" ] }, { "cell_type": "code", "execution_count": 22, "id": "placed-thong", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, World!\n", "None\n", "\n" ] } ], "source": [ "def hello_world():\n", " print(\"Hello, World!\")\n", "functions_output = hello_world()\n", "print(functions_output)\n", "print(type(functions_output))" ] }, { "cell_type": "markdown", "id": "amended-drunk", "metadata": {}, "source": [ "很多的時候光是將物件以 `print()` 函數印出不足以判斷該物件的資料型別為何,像是下列的程式碼看不出來究竟是字串、布林或者 None。" ] }, { "cell_type": "code", "execution_count": 23, "id": "received-quarterly", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "None\n", "False\n", "None\n" ] } ], "source": [ "a_string = \"False\"\n", "another_string = \"None\"\n", "bool_false = False\n", "none_type = None\n", "print(a_string)\n", "print(another_string)\n", "print(bool_false)\n", "print(none_type)" ] }, { "cell_type": "markdown", "id": "thick-ready", "metadata": {}, "source": [ "這時候除了對物件應用內建函數 `type()` 之外,還能夠用其他內建函數協助判斷以及轉換資料型別。\n", "\n", "## 判斷資料型別的函數\n", "\n", "使用 `isinstance(x, classinfo)` 函數判斷輸入物件是否為某個資料型別,其中 `x` 輸入物件名稱、 `classinfo` 參數輸入資料型別名稱。" ] }, { "cell_type": "code", "execution_count": 24, "id": "informational-integrity", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "False\n", "True\n", "False\n", "True\n", "False\n", "True\n", "False\n" ] } ], "source": [ "# Check if input is an int\n", "print(isinstance(5566, int))\n", "print(isinstance(\"5566\", int))\n", "# Check if input is a float\n", "print(isinstance(5566.0, float))\n", "print(isinstance(5566, float))\n", "# Check if input is a str\n", "print(isinstance(\"True\", str))\n", "print(isinstance(True, str))\n", "# Check if input is a bool\n", "print(isinstance(False, bool))\n", "print(isinstance(\"False\", bool))" ] }, { "cell_type": "markdown", "id": "amazing-processing", "metadata": {}, "source": [ "## 轉換資料型別的函數\n", "\n", "使用與目標轉換型別同名的函數轉換資料型別。\n", "\n", "- `int()`:轉換為整數型別。\n", "- `float()`:轉換為浮點數型別。\n", "- `bool()`:轉換為布林型別。\n", "- `str()`:轉換為文字型別。\n", "\n", "使用 `int()` 函數可以輸入浮點數、布林與文字讓 Python 轉換成整數。" ] }, { "cell_type": "code", "execution_count": 25, "id": "opening-going", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5566\n", "1\n", "0\n", "5566\n" ] } ], "source": [ "print(int(5566.0))\n", "print(int(True))\n", "print(int(False))\n", "print(int(\"5566\"))" ] }, { "cell_type": "markdown", "id": "cathedral-confidence", "metadata": {}, "source": [ "使用 `float()` 函數可以輸入整數、布林與文字讓 Python 轉換成浮點數。" ] }, { "cell_type": "code", "execution_count": 26, "id": "inclusive-custom", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5566.0\n", "1.0\n", "0.0\n", "5566.0\n" ] } ], "source": [ "print(float(5566))\n", "print(float(True))\n", "print(float(False))\n", "print(float(\"5566\"))" ] }, { "cell_type": "markdown", "id": "latter-trinity", "metadata": {}, "source": [ "使用 `bool()` 函數可以輸入整數、浮點數與文字讓 Python 轉換成布林,輸入浮點數或整數類型的 0 會轉換成為 `False`,其他數字則一律轉換為 `True`,若輸入文字,無論輸入文字內容為何都一律轉換成 `True`。" ] }, { "cell_type": "code", "execution_count": 27, "id": "worthy-special", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "False\n", "True\n", "True\n", "True\n", "True\n", "True\n", "True\n", "True\n", "True\n", "True\n", "True\n" ] } ], "source": [ "print(bool(0))\n", "print(bool(0.0))\n", "print(bool(1))\n", "print(bool(1.0))\n", "print(bool(5566.0))\n", "print(bool(-5566.0))\n", "print(bool(\"True\"))\n", "print(bool(\"TRUE\"))\n", "print(bool(\"true\"))\n", "print(bool(\"False\"))\n", "print(bool(\"FALSE\"))\n", "print(bool(\"false\"))" ] }, { "cell_type": "markdown", "id": "prescribed-version", "metadata": {}, "source": [ "使用 `str()` 函數可以輸入整數、浮點數與布林讓 Python 轉換成文字。" ] }, { "cell_type": "code", "execution_count": 28, "id": "acute-rates", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5566\n", "5566.0\n", "True\n", "False\n" ] } ], "source": [ "print(str(5566))\n", "print(str(5566.0))\n", "print(str(True))\n", "print(str(False))" ] }, { "cell_type": "markdown", "id": "polished-literature", "metadata": {}, "source": [ "在轉換資料型別的過程,我們從布林、整數、浮點數最後到字串,這個順序並不是任意編排的,而是有意識地從資料的子集合逐漸往母集合提升,例如布林被包含於整數(0 與 1)之中、整數被包含於浮點數之中、而任何數值都能夠用字串去表示。這也意味著,如果我們試圖反向地從母集合往子集合轉換,資料型別的轉換並不保證能成功。" ] }, { "cell_type": "code", "execution_count": 29, "id": "healthy-bullet", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "could not convert string to float: 'True'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"True\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: could not convert string to float: 'True'" ] } ], "source": [ "print(float(\"True\"))" ] }, { "cell_type": "markdown", "id": "lyric-family", "metadata": {}, "source": [ "在認識五種基礎資料型別、判斷與轉換資料型別函數之後,Python 的資料型別這篇文章來到尾聲。\n", "喜歡這篇文章嗎?訂閱數據交點 可以收到我的電子報😻\n", "\n", "## 延伸閱讀\n", "\n", "- [Python String format() Method](https://www.w3schools.com/python/ref_string_format.asp)" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 5 }