First, I know python-----everyone loves the list

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.