Python3.x Study Notes 3, python3.x Study Notes

Source: Internet
Author: User

Python3.x Study Notes 3, python3.x Study Notes

1. Set
A set is an unordered, non-repeated data combination. Its function is as follows:
> Deduplication: automatically removes duplicates when a list is converted to a set.
> Link test: tests the intersection, difference set, and union of the two groups of data.

2. relational operation

Intersection: set1.intersection (set2)
Union: set1.union (set2)
Difference set: set1.difference (set2) # In set1, set2 does not
Subset: set1.issubset (set2) # determine whether set1 is a subset of set2
Parent set: set1.issuperset (set2) # determines whether set1 is the parent of set2.
Symmetric difference set: set1.symetric _ difference (set2) # Remove the union of the two sets, and retrieve them none.
Determine whether there is an intersection: set1.isdisjoint (set2)

3. Operator relationship Calculation
Intersection :&
Union: |
Difference set :-
Symmetry difference set: ^
Subset: <=
Parent set:> =

4. Basic Set Operations
Add: set1.add (x) # add an item
Update: set1.update ([10, 37, 45]) # add multiple
Remove: set1.remove () # You can delete an item. If it does not exist, an error is returned.
Remove: set1.discard () # remove an item. If it does not exist, no error is returned. The return value is none.

Measurement length: len (set1)

X in set1 # test whether x is a member of set1
X not in set1 # test whether x is not a member of set1
Shortest: set1.copy ()
Set1.pop () # delete any set1zhong Element

 

5. File Operations
(1) open the file, get the file handle, and assign a value to a variable.
(2) operate the file through a handle
(3) close the file
6. File Operations
Https://www.cnblogs.com/nulige/archive/2016/12/06/6037752.html

 

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.