课程: Python Practice: Collections
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Modify a tuple
- [Instructor] To solve this challenge, I need to use the values from the original topple and the new value, and I need to insert that new value at the specified index. So, I start by using slicing to get the items in the original topple, starting from the beginning through the value of index. The colon here without a number before it means to start at the beginning of a collection and then index following it means to stop when it reaches that value. So for example, if the value of index was four, this portion of code would represent items 0, 1, 2, and 3. Then I use plus and the new value followed by a comma in parentheses to add the new value. Without the comma, this value would be treated as a string and we can't concatenate a string to topple values. And because the first part over here contains the values up to where I wanted this item to be, this item will be in the correct place. After this, I add the rest of the…