Python Learning: list, tuple, and dict

Source: Internet
Author: User

List: Lists, data types can be different

Definition: (example) classmates = [' Michael ', ' Bob ', ' Tracy ']

Access to an element: (example) classmates[0] means access to the first element (example) classmates[-1] means access to the last element

Get list Length: (example) Len (classmates)

Append elements: (example) classmates.append (' Adam ')

Insert element to specified position: (example) Classmates.insert (1, ' Jack ')

Delete End element: (example) Classmates.pop ()

Delete the specified element: (example) Classmates.pop (1)

Replace the specified element: (example) classmates[1] = ' Sarah '

Two-dimensional list: (example) p = [' asp ', ' php ']

s = [' Python ', ' Java ', p, ' scheme ']

S[2][1] is ' php '

Tuple: Tuples, once initialized cannot be modified

Define an empty tuple: (example) T = ()

Define a single element tuple: (example) T = (1,) (in order to differentiate between expressions (1) and tuple (1))

"Mutable" tuple: (example) t = (' A ', ' B ', [' A ', ' B ']) (description: The contents of a tuple are not mutable, but the contents of the list can be changed)

Dict: Dictionary, key-value mapping store, very fast lookup speed

Python Learning: list, tuple, and dict

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.