Python, I learned from scratch t^t D3

Source: Internet
Author: User

Recently to go back to school to do the completion of the set, ready to do a related algorithm, I heard that Python operations better, specifically to learn.

Let's start with the basics .......... ...........

D3

1.set elements are not duplicated, no order. Can be a tuple type

1 #the way to create a set is to call set () and pass in a list,list element as the set element:2 3>>> s = Set (['A','B','C'])4 5>>>Prints6Set (['A','C','B'])7 8>>> s = Set (['A','B','C','C'])9>>>PrintsTenSet (['A','C','B']) One>>>Len (s) A3
1>>>s = Set ([('Adam', 95), ('Lisa', 85), ('Bart', 59)])2>>> forXinchS:3>>>PrintX[0],':', x[1]4 5 #lisa:856 #adam:957 #bart:59

2. Access set content can be used in. The speed is very fast, the content is immutable and cannot be changed. Facilitates finding specific keywords in ' dictionaries '.

>>> ' Hello ' in s

False

>>> ' A ' in S

True

>>> ' A ' in S

False

Case sensitive, case default is not the same character

The 3.set traversal method can be used for loops

>>> for X in S

>>>>>>print x

A

4.set.add (' element ') adds an element to the set, and Set.remove (' element ') removes the element from the set.

Where an existing element is added, no error is made, and it is not added. Deleting an element that does not exist will cause an error.

Python, I learned from scratch t^t D3

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.