在Python中,是否可以向内置类添加新方法,例如Tuple。我想添加 2 个新方法:first() 返回元组的第一个元素,second() 返回一个没有第一个元素的新元组。
例如:
x = (1, 2, 3) x.first() # 1 x.second() # (2, 3)
谢谢
python tuples
python ×1
tuples ×1