Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 39ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
t

tutorial-example

Recently created Least recently created Recently updated Least recently updated

timmy / dataclass 與 NamedTuple 差異範例

Last active 5 hours ago data-structure dataclass namedtuple python tutorial-example type-hints

示範 Python 中 dataclass 與 NamedTuple 的基本使用方式與差異,包含屬性定義、建立實例、存取欄位、是否可變等特性。

0 0 0 2
1 from dataclasses import dataclass
2
3 @dataclass
4 class Person:
5 name: str
6 age: int
7 email: str
8
9 # 建立實例
10 person1 = Person(name="Timmy", age=30, email="timmy@example.com")