Creation and access of Python lists
Movies = ["the Holy Grail","the Life ofBrian"," The meaningof life"]print(movies[1])
List of commonly used BIF
Print () display list contents
Len () calculates the data item for the list
Append () Adds a data item at the end of the list extend () adds a collection of data items at the end of the list
Pop () delete data from the end of the list
Remove () to locate and delete a specific data item
Insert () Adds a data item before a specific position
cast = ["Cleese","Palin","Jones","Idle"]Print(CAST)Print(len (CAST)) Cast.append ("Gilliam") //add Cast.pop at the end ()//Delete End data Cast.extend (["Gilliam","Chapman"]) //Add a data set Cast.remove ("Cleese") //Delete a specific item cast.insert (0,"Chapman")//Add one item before position 0
For loops in Python
Movies = ["TheHoly Grail","the Life ofBrian")for in movies: print(each)
Query Python built-in methods and function descriptions
Dir (__builtins__) // Built-in method list Help ( input)//Get Input () function description of this function
How Isinstance () works
names = ['Michael','Terry'//=// This sentence returns false
Use recursion to create a function iteration output with nested lists
Movies = ["The Holy Grail", 1975,"Terry Jones & Terry Gilliam", 97, ["Graham Chapman",["Michael Palin","John Cleese", "Terry Gilliam","Eric Idle","Terry Jones"]]]defprint_lol (the_list): forEach_iteminchthe_list:ifisinstance (each_item,list): Print_lol (Each_item)//Recursive invocationElse: Print(Each_item) print_lol (Movies)
First, I know python-----everyone loves the list