You can download this code by clicking the button below.
This code is now available for download.
This function creates a Rich library's Table component to display tabular data containing names, ages, and countries. Using Rich's Table class, columns and rows can be easily added, and styles can be set.
Technology Stack : Rich, Table
Code Type : Table component application of Rich library
Code Difficulty : Intermediate
def rich_table_example(data):
from rich.console import Console
from rich.table import Table
console = Console()
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Name", justify="left")
table.add_column("Age", justify="right")
table.add_column("Country", justify="left")
for row in data:
table.add_row(row[0], str(row[1]), row[2])
console.print(table)
# Usage example
data = [
["Alice", 30, "USA"],
["Bob", 25, "UK"],
["Charlie", 35, "Canada"]
]
rich_table_example(data)