Python language, append (), extend (), and the Insert () method are used to see the addition of more data to the list.
Both append and extend require only one parameter and are automatically added to the end of the array, and if you need to add more than one, the array can be nested, but append is the nested array as an object.
Extend is to add nested array contents as multiple objects to the original array
As the basis of programming 0 small white, feel the need to comb it again:
The 1.append () method refers to adding a data item at the end of the list.
For example, add the "Gavin" item at the end of the students list.
>>>students = [' Cleese ', ' Palin ', ' Jones ', ' Idle ']>>> students.append (' Gavin ') >>> print ( Students) [' Cleese ', ' Palin ', ' Jones ', ' Idle ', ' Gavin ']
The 2.extend () method refers to adding a collection of data at the end of the list.
For example: in Example 1, the end of the students list continues to add three entries for "Kavin" and "Jack" and "Chapman".
>>> students = [' Cleese ', ' Palin ', ' Jones ', ' Idle ']>>> students.append (' Gavin ') >>> print (St udents) [' Cleese ', ' Palin ', ' Jones ', ' Idle ', ' Gavin ']>>> students.extend ([' Kavin ', ' Jack ', ' Chapman ']) > >> print (students) [' Cleese ', ' Palin ', ' Jones ', ' Idle ', ' Gavin ', ' Kavin ', ' Jack ', ' Chapman ']
The 3.insert () method refers to the addition of a data item in front of a specific location.
For example: Add "Gilliam" before "Palin" in the students original list.
>>> students = [' Cleese ', ' Palin ', ' Jones ', ' Idle ']>>> students.insert (1, ' Gilliam ') >>> prin T (students) [' Cleese ', ' Gilliam ', ' Palin ', ' Jones ', ' Idle '].
Since data items are stacked from bottom to top, the first data in the stack is numbered 0 and the second data is 1, so it is Students.insert (1, ' Gillam ').
The difference between append, Extend, and insert methods in Python