Python Learning Dict (dictionary) type and set type

Source: Internet
Author: User

To create a dictionary type:

Zidian = {} or Zidian = Dict ()

[]: Use the index inside square brackets

Len (Zidian): Number of test key-value pairs

In: Whether the key is in the dictionary, returns a Boolean value

Dictionary method:

Items (): A list of tuples for all key-value pairs

Keys (): List of all keys

VALUES (): All Worthwhile lists

Copy (): Shallow copy Dictionary

To create a set type:

Nullset=set ()

Dictionary method:

Len (); Number of elements

Intersection: Create a new collection, take the same part of the two collection intersection () such as Aset.intersection (Bset)

Aset.union: Create a new collection, remove all elements of two collection (Bset)

Difference set: Aset.difference (Bset)

Symmetry difference: Remove elements that are not shared in the two collection symmetric_difference

Subset and superset: Aset.issubset (Bset), Aset.issuperset (Bset) return value is Boolean

Add (Element)

Clear (): Empty

Remove (Element) and discard (element): Deletes the elements. element does not exist remove error, discard () does not

Copy (): Shallow copy




This article is from the "leaf" blog, please be sure to keep this source http://fshine.blog.51cto.com/6122608/1569878

Python Learning Dict (dictionary) type and set type

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.