Python Learning Note Day3

Source: Internet
Author: User

set a bit:1, access Speed 2, born to solve the problem of repetition

Tuple differs from set: tuple repeatable, set not repeatable
Gen Jie Collection 1

>>> S1.add (' Alex ')
>>> Print (S1)
{' Alex '}
>>> S1.add (' Alex ')
>>> Print (S1)
{' Alex '}

Create a Collection 2
>>> set ([' Alex ', ' Eric ', ' Tony ')
{' Tony ', ' Eric ', ' Alex '}

Find the difference and rebuild a new collection
>>> S1 = set ([' Alex ', ' Eric ', ' Tony ')
>>> s1.diference ([' Alex ', ' Eric '])
{' Tony '}

>>> S1 = set ([' Alex ', ' Eric ', ' Tony ')
>>> s1.difference ([' Alex ', ' Eric '])
{' Tony '}
>>> s2=s1.difference ([' Alex ', ' Eric '])


>>> S2
{' Tony '}
>>> Print (s2)
{' Tony '}


Difference_update Modify the original collection to present the specified element

>>> S1
{' Tony ', ' Eric '}
>>> s3 = S1.difference_update ([' Tony '])
>>> S1
{' Eric '}

Pop takes an element from the original collection and can accept the element with another variable.

>>> S1 = set ([' Alex ', ' Eric ', ' Tony ')
>>> s2 = S1.pop ()
>>> S2
' Alex '
>>> S1
{' Tony ', ' Eric '}
>>>

Python Learning Note Day3

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.