Python provides methods that operate on lists. For example, append adds a new element to the end of a list, extend takes a list as an argument and appends all of the elements:
And this example leaves t1 unmodified.
sort arranges the elements of the list from low to high:
List methods are all void; they modify the list and return None. If you accidentally write t = t.sort(), you wiil be disappointed with the result.
from Thinking in Python
时间: 2024-12-06 17:20:08