Copy codeThe Code is as follows:
Python 3.3.4 (v3.3.4: 7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license ()" for more information.
>>> Cast = ["cleese", "palin", "jones", "idle"]
>>> Print (cast)
['Cleese ', 'palin', 'Jones', 'idle']
>>> Print (len (cast) # display the number of data items
4
>>> Print (cast [1]) # display the values of the first data item in the list
Palin
>>> Cast. append ("gilliam") # Add a data item to the end of the list.
>>> Print (cast)
['Cleese ', 'palin', 'Jones', 'idle', 'gillim']
>>> Cast. pop () # delete data items at the end of the list
'Gilliam'
>>> Print (cast)
['Cleese ', 'palin', 'Jones', 'idle']
>>> Cast. extend (["gilliam", "chapman"]) # Add a data item set at the end of the list.
>>> Print (cast)
['Cleese ', 'palin', 'Jones', 'idle', 'gillim', 'chapman']
>>> Cast. remove ("chapman") # delete a specified data item
>>> Print (cast)
['Cleese ', 'palin', 'Jones', 'idle', 'gillim']
>>> Cast. insert (0, "chapman") # add data items to a specified position
>>> Print (cast)
['Chapman ', 'cleese', 'palin', 'Jones ', 'idle', 'gillim']
>>>
The following describes the application and logic of defining a def function, isinstance () function, for in, if else, and so on.
Copy codeThe Code is as follows:
Movies = ["the holy grail", 1975, "terry jone & terry gilliam", 91,
["Graham chapman ",
["Michael palin", "john cleese", "terry gilliam ",
"Eric idle", "terry jones"]
Def print_lol (the_list): # define a function
For each_item in the_list: # for in loop iteration processing list, from the starting position of the list to the end
If isinstance (each_item, list): # isinstance () Checks each item in each_item
# Is it list type?
Print_lol (each_item) # If yes, call the print_lol function.
Else: print (each_item) # If not, output this item
Print_lol (movies) # Call the function in the movies list
"""
If the else statement is not aligned, an error is reported.
"""