Python Foundation 07set set of shades and copies

Source: Internet
Author: User
Tags set set shallow copy

The main contents of this section :
1. Basic Data type supplement
2. Set Set
3. The depth of the cuff?

"". Join method

To iterate through the contents of the list:

of the wrong

Cause: In the For loop, loop to the first, then delete, delete the second element to move forward, the loop pointer backward one bit, and then delete, the result will cause 22,44 not deleted.

only in this way is it possible :

Note: Because deleting an element will cause the element index to change, so delete the element is, try not to delete in the original place, try to create a new and then go to bulk Delete

The Fronkey () in Dict can help us create a dict from the list.

Each of the pre-column tables? Items are treated as key, and the contents of the Post-column table as value. ? into dict
It's all right . Note :

Since the code Jay and JJ use the same list, you should change the

Idea: The elements in the dict are not allowed to be deleted during the iteration, and if you want to delete them, create a new one as well as the same as the previous list Delete method.

Type conversions:

Tuple-->>list list (tuple)

List-->>tuple Tuple (list)

List--->>> string "". Join () method

String--->>> list split cut

0, "", None, [], {}, (), set ()----->>>> can be converted to false

Two, set set

set element is not repeat .. < Span class= "Fontstyle2" > element must be (int, str, tuple,bool)

Note : The elements in the set set must be hash , but the set body is not a hash the. Set is Variable .

Set collection and deletion and modification:

Increase:

. Add () duplicate content is not updated

. Update () Iteration Updates

Delete:

Pop () randomly pops up a

. Remove () to delete the specified content, the error is not present    

.clear ()      emptying set Set . It is important to note that the set print out is set () because to and dict differentiated .

Modify:

The collection does not have an index and cannot be positioned, so the modification can only be deleted in the add

Check: For loop iteration

<<<<<<-----------Other Operations------------>>>>>>>

Three-depth copy:

Shallow copy data unchanged

Deep copy data changes

Younger brother Caishuxueqian, sentiment not too much, oneself feel the depth copy is a bug, have a friend can discuss together.

Python Foundation 07set set of shades and copies

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.