Hướng dẫn add tuple values python
In Python, since Show
This article describes the following contents.
Note that, although words such as "add", "change", and "remove" are used for convenience, in reality, a new object is generated, and the original object is not updated. tuple is immutableUse the following tuple as an example.
You can get elements by index
Since
Destructive methods (= methods that update the original object) such as
Append an item to tuple
Only tuples can be concatenated. It cannot be concatenated with other types such as
If you want to append an item to a tuple, you can concatenate a tuple with one element.
Note that a tuple with one element requires a comma at the end.
Add/insert items to tupleIf you want to add new items at the beginning or the end to Convert
Insert an item with
Convert
Change items in tupleYou can change items of the tuple in the same way. Convert
Remove items in tupleYou can also remove items of the tuple in the same way.
In the above example,
|