Python list tuple dictionary

Source: Internet
Author: User

First, List

A set of ordered items. variable data type "can be added and censored"

A list is a collection of data surrounded by square brackets "[]", with different members separated by ",".

The list can contain any data type, or it can contain another list

Lists can access members by ordinal

Common list operations:

List.append () Append member, member data

List.pop () Delete Members, delete member I

List.count (x) calculates the number of occurrences of the parameter X in the list

List.remove () Remove members from list, delete members directly I

List.extend (l) Append another list to the list L

List.reverse () Reverses the order of the members in the list

List.index (x) Gets the position of the parameter X in the list

List.sort () sort the members in the list

List.insert () inserting data into the list insert (A, B) inserts data into the list

Two, the meta-group

Immutable Sequences

A tuple is a collection of data surrounded by parentheses "()", with different members separated by ","

Unlike lists: the data in a tuple cannot be changed once it is established

Access by subscript

Statement:

L= (a)

Tuples with 0 elements: L = ()

Tuples with 1 elements: l= (1,) note a comma

Third, the dictionary

A collection of key-value pairs (map)

A dictionary is a collection of data surrounded by curly braces "{}"

Differences from lists: Dictionaries are unordered , and members are accessed through keys in the dictionary.

The dictionary is mutable and can contain any other type

Statement:

M={K1:V1,K2:V2}

Access M[K1] will get V1

Common Dictionary operations:

Dic.clear () Empty dictionary

Dic.keys () Get a list of keys

Dic.values () Get a list of values

Dic.copy () Copy Dictionary

Dic.pop (k) Delete key k

Dic.get (k) Gets the value of the key K

Dic.update () Update member, if member does not exist, equivalent to join

Dic.items () Gets a list of keys and values

Dic.popitem

Python list tuple dictionary

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.