Lecture 8 Review and Feedback

1. Modify a list, a string, or a tuple.





2. .append() and .extend() applied to a list:



'extend()' makes the original list longer using one or multiple elements.

'append()' directly attaches 'a' PACKAGE to the end of the original list, just one element (can be a str, an int, or a list).

Tuple doesn't have 'extend()' and 'append()' attributes/methods.

3. Lecture 4, task 5


Solution:


4. Lecture 3, task 5


Solution:



However, if you only remove 'b' from the list and using 'method 3', you need to be careful. The index '[1]' won't work.
'

However, index '[1:2]' works.


You can understand it in this way:
Index '[1]' only represents the single string 'b', which doesn't include the 'comma' before and after it.
However, index '[1:2]' represents the string 'b' and the 'comma' after it, which is actually  ---  'b',

You do need to take the 'comma' out when you want to take out the single element. Otherwise, the spot will still be there and you have to have something to fill up the spot.