Python's Set function

Source: Internet
Author: User

Str

List---Lists

Tuple

DIC----Dictionary

Set

Function

-Custom functions

-built-in functions > Python-provided functions that call directly

Depth copy

Decorative Device

List characteristics: Ordered, the elements can be repeated, the dictionary key cannot be duplicated;

1.set-unordered, non-repeating sequence;

Cases:

List = [11,22,11,22]--Types of lists

DIC = {"K1": 123}--Dictionary type

A. Creating a set collection (function)

SE = {"123", "456"}--collection type

Print (Type (set))

List ()--class after addition () parentheses, which represents the invocation of the __init__ method;

list__init__, internal execution for loop (11,22,33,44) List--[11,22,33,44]

S1 = {11,22}

S2 = set ()

S3 = Set ([11,22,33,44])

B. function

s = Set () creates an empty collection;

To convert a list to a collection:

List = [11,22,11,22]

S1 = set (list)

Print (S1)

Operation Collection:

S1 = set ()

S1. Add (123)

Print (S1)

S1.clear ()

Print (S1)

S2 = {121,3132,22,11}

S1.difference (S2)

S3 = s1.symmetric_difference (S2)

Print (S3)

S1.discard (123)--Remove the specified element

S1.pop ()--random removal of an element

ret = S1.pop ()---Remove an element and assign the element to RET

S1.update (list)--iterate to add elements


Python's Set function

Related Article

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.