10 collections of zero-Basic Python basics

Source: Internet
Author: User
The ten collections of the zero-basic introduction to Python first remember several features of the set: the set is unordered, and the elements in the set are unique.
1. set definition
The definition of a set is very similar to that of a dictionary. you only need to convert the key-value pairs in the dictionary into elements.

Num = {1, 2, 3, 4, 5} print (type (num) print ("\ n") # Duplicate data is automatically removed from the set, and the set is also unordered num2 = {1, 2, 3, 4, 5, 4, 32} print (num2) print ("\ n ")

(2) use the set () factory function

Set1 = set ([1, 2, 3, 4, 5, 6]) print (set1)

(3) use frozenset () to create an unchangeable set: Once a set is created, the set cannot be modified; otherwise, an exception occurs.

Num3 = frozenset ([1, 2, 3, 4, 5]) num3.add (6)

The above is a set of 10 things for getting started with Python. For more information, see The PHP Chinese website (www.php1.cn )!

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.