Python Beginner Eighth Day

Source: Internet
Author: User

8day

1. Data type: Tuple

Tuples: A collection of ordered, immutable data. However, if you include other mutable elements, these elements are variable. Shown to tell others, here can not be modified;

A = (1,2,3,4,5,[' 1 ', ' a '])

2. Data type: Dictionary

Dictionary: Dictionary is a kind of key-value data type, use like the dictionary that we use to go to school, check the detailed content of the corresponding page by pen stroke, letter;

Characteristics:

-Unordered

-Fast Search speed

-can store any number of values, can be modified, can not be unique

-key-value structure

-key must be hash, must be immutable data type, must be unique

2.1 Basic operation of the dictionary:

2.1.1 Delete

A, pop delete

B, Popitem random deletion

Dict.popitem ()

C, del Delete

Del Dict[key]

D, clear clear

2.1.3 Increase

A. Direct Plus

Dict[key]=value If there is a replacement, if none is added

2.1.4 Modification

2.1.5 Get

Dict.get (key), if any, returns the corresponding value. If none, then return "None"

Dict[key]=value

K in dict determines if there is a key, returns true if any, or false if none

2.2 Common operations:

Dict.keys all key values of the output dictionary

Dict.value all value values of the output dictionary

Dict.items the dictionary into a list

Dict.update (DICT2) merges two dictionaries. If you have the same key, overwrite it. Without the same key, create the

Dict.setdefault (Key,value) If you have this key, return value. If not, create a

Fromkeys converting a list to a dictionary

Python Beginner Eighth Day

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.