Today's learning content is related to the list in Python.
I. Create a list
1. Create a normal list
>>> Tabulation1 = [' The Holy Man ', ' canopy ', ' roll the curtain ']>>> tabulation1[' st ', ' canopy ', ' roller blinds ']
>>> Tabulation2 = [72,36,18]>>> tabulation2[72, 36, 18]
2. Create a mixed list
>>> Mix tabulation = [' The Holy Man ', 72, ' canopy ', 36]syntaxerror:invalid syntax>>> mixtabulation = [' The sage ', 72, ' canopy ', 36 ]>>> mixtabulation[' Holy Sage ', 72, ' canopy ', 36]
3. Create an empty list
>>> empty = []>>> empty[]
There are three ways to introduce you, and next, what do you do if you want to add elements to the list?
Two. Adding elements to the list
1.append
>>> tabulation1.append (' Purple Chardonnay ')
>>> Tabulation1
[' The Holy Man ', ' canopy ', ' roller blinds ', ' violet Chardonnay ']
2.extend
>>> tabulation1.extend ([' Purple Chardonnay ', ' Green Xia '])
>>> Tabulation1
[' The Holy Man ', ' canopy ', ' roller blinds ', ' Purple Chardonnay ', ' Purple Chardonnay ', ' Green Xia ']
There is a way to expand the list with extend, and it is important to note that this method uses a list to expand the list instead of adding elements directly, so add "[]" to "()".
3.insert
>>> Tabulation1.insert (1, ' Purple Chardonnay ') >>> tabulation1[' Holy sage ', ' Purple Chardonnay ', ' canopy ', ' roller blinds ', ' Purple Chardonnay ', ' Purple Chardonnay ', ' green Chardonnay '
Do not want to eat in situ and so die, so I choose to progress a little bit every day.
Python create list and add element method to list