Python list and tuple operations

Source: Internet
Author: User

List:

Definition list:

shoppinglist=[' car ', ' clother ', ' iphone ']

0 1 2

Remove Clother from the list

SHOPPINGLIST[2]

Like the last add in the list

Shoppinglist.append (' Oldboy ')

Insert Insert 2 in front of image list

Shoppinglist.insert (' 2 ', ' Oldboy ')

Count, find how many times Oldboy appear in the table

Shoppinglist.count (' Oldboy ')

The count can be used as a judgment: no return 0

There is no oldboy in the judging list:

' Oldboy ' in shoppinglist

Query index, return the position of Oldboy in the list

Shoppinglist.index (' Oldboy ')

Delete (if there are more than one in the list, the first one is deleted by default)

Shoppinglist.remove (' Oldboy ')

Delete Last

Shoppinglist.pop ()

Sort

Shoppinglist.reverse ()

Sort by alphabet

Shoppinglist.sort ()

modifying list data

shoppinglist[1]= ' Oldboy '

For example:

I=shopping.index (' Oldboy ')

shopping[i]= ' Newoldboy '

To generate a list of string variables:

names = "Alex Dongxu feiferi"

Names_list=names.split ()

Built-in function min, the minimum value given in the search list

Main (list)

Meta-group:

Tuples are the same as lists, but not tuple one but the build cannot be modified


Python list and tuple operations

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.