Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the non-repeatable data set Set in python

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to understand the non-repeatable data set in python, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, people who have this need can learn, I hope you can gain something.

If you want to keep data from repeating, you need to use Set.

Note: Set initialization is contained with "{}", List initialization is contained with "[]".

provinces = {'Zhejiang',' Jiangsu','Shanghai',' Shanghai'}

When initializing provinces, there are two "Shanghai". When displayed, there is only one "Shanghai", indicating that the Set will be automatically de-weighted. There is also a point. Careful friends may have discovered that the order of elements in provinces has changed, not the order of initialization, indicating that the Set is disordered.

You can use in to determine if an element is in a collection:

Returns "True" if it is in the collection, returns "False" if it is not in the collection.

There is also a quick way to create collections:

The set() method lets you break a string into sets alphabetically.

It is also possible to perform operations between sets:

a-b denotes a set whose elements are in a but not in b

a |b represents the set of elements in a or b

a & b represents a collection of elements in a and in b

a ^ b denotes a set of elements only in a or only in b

Set cannot contain duplicate elements, and is unordered, and sets can be "-","|","&","^"operation Oh.

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report