Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
## インストール
pip install tabulate
## pythonでのコード例
from tabulate import tabulate
data = [
["toro", 20, "neko"],
["kuro", 19, "neko"],
["jun", 18, "usagi"],
]
## インストール pip install tabulate ## pythonでのコード例 from tabulate import tabulate data = [ ["toro", 20, "neko"], ["kuro", 19, "neko"], ["jun", 18, "usagi"], ]
## インストール
pip install tabulate


## pythonでのコード例
from tabulate import tabulate

data = [
    ["toro", 20, "neko"],
    ["kuro", 19, "neko"],
    ["jun", 18, "usagi"],
]
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
## テーブルフォーマット指定なし
table = tabulate(data, headers=["name", "age", "tribe"])
print(table)
name age tribe
------ ----- -------
toro 20 neko
kuro 19 neko
jun 18 usagi
## テーブルフォーマット指定なし table = tabulate(data, headers=["name", "age", "tribe"]) print(table) name age tribe ------ ----- ------- toro 20 neko kuro 19 neko jun 18 usagi
## テーブルフォーマット指定なし

table = tabulate(data, headers=["name", "age", "tribe"])
print(table)

name      age  tribe
------  -----  -------
toro       20  neko
kuro       19  neko
jun        18  usagi

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
## テーブルフォーマット=gridの時
table1 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='grid')
print(table1)
+--------+-------+---------+
| name | age | tribe |
+========+=======+=========+
| toro | 20 | neko |
+--------+-------+---------+
| kuro | 19 | neko |
+--------+-------+---------+
| jun | 18 | usagi |
+--------+-------+---------+
## テーブルフォーマット=gridの時 table1 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='grid') print(table1) +--------+-------+---------+ | name | age | tribe | +========+=======+=========+ | toro | 20 | neko | +--------+-------+---------+ | kuro | 19 | neko | +--------+-------+---------+ | jun | 18 | usagi | +--------+-------+---------+
## テーブルフォーマット=gridの時

table1 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='grid')
print(table1)

+--------+-------+---------+
| name   |   age | tribe   |
+========+=======+=========+
| toro   |    20 | neko    |
+--------+-------+---------+
| kuro   |    19 | neko    |
+--------+-------+---------+
| jun    |    18 | usagi   |
+--------+-------+---------+

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
## テーブルフォーマット=fancy_gridの時
table2 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='fancy_grid')
print(table2)
╒════════╤═══════╤═════════╕
│ name │ age │ tribe │
╞════════╪═══════╪═════════╡
│ toro │ 20 │ neko │
├────────┼───────┼─────────┤
│ kuro │ 19 │ neko │
├────────┼───────┼─────────┤
│ jun │ 18 │ usagi │
╘════════╧═══════╧═════════╛
## テーブルフォーマット=fancy_gridの時 table2 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='fancy_grid') print(table2) ╒════════╤═══════╤═════════╕ │ name │ age │ tribe │ ╞════════╪═══════╪═════════╡ │ toro │ 20 │ neko │ ├────────┼───────┼─────────┤ │ kuro │ 19 │ neko │ ├────────┼───────┼─────────┤ │ jun │ 18 │ usagi │ ╘════════╧═══════╧═════════╛
## テーブルフォーマット=fancy_gridの時

table2 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='fancy_grid')
print(table2)

╒════════╤═══════╤═════════╕
│ name   │   age │ tribe   │
╞════════╪═══════╪═════════╡
│ toro   │    20 │ neko    │
├────────┼───────┼─────────┤
│ kuro   │    19 │ neko    │
├────────┼───────┼─────────┤
│ jun    │    18 │ usagi   │
╘════════╧═══════╧═════════╛
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
## テーブルフォーマット=githubの時
table3 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='github')
print(table3)
| name | age | tribe |
|--------|-------|---------|
| toro | 20 | neko |
| kuro | 19 | neko |
| jun | 18 | usagi |
## テーブルフォーマット=githubの時 table3 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='github') print(table3) | name | age | tribe | |--------|-------|---------| | toro | 20 | neko | | kuro | 19 | neko | | jun | 18 | usagi |
## テーブルフォーマット=githubの時

table3 = tabulate(data, headers=["name", "age", "tribe"], tablefmt='github')
print(table3)

| name   |   age | tribe   |
|--------|-------|---------|
| toro   |    20 | neko    |
| kuro   |    19 | neko    |
| jun    |    18 | usagi   |

おすすめの記事