Python 5.7

Source: Internet
Author: User

First, the basic data type supplement

#数据类型的补充
#元祖tuple, if there is an element in it and there is no comma, the data type is the type of the unique element.
# tu = ([[+]) #tu里面只有一个列表, without commas. The data type is list.
# Print (Tu,type (TU))
# tu = ([[+)], #里面虽然只有一个元素, but followed by a comma. or the Ganso type.
# Print (Tu,type (TU))
#for Loop, it is best not to iterate through the elements in the list or dictionary, changing the size of the list and dictionary. Will go wrong.
#解决办法, list, reverse loop, so it doesn't change the size of the list.
# li = [' Liujj ', ' xiaol ', ' jisp ')# for I in range (Len (LI) -1,-1,-1): #range顾头不顾腚, so the tail is 0-1=-1,len () peso is 1 more, so Len ()-1, when Len () as the tail,
# if I% 2 = = 1: #如果从0开始循环, Len () does not need-1.
# Li.pop (i)
# Print (LI)
#解决办法, dictionary, put the key you want to delete into a list, loop the list, and then delete the dictionary.
# dic = {' K1 ': ' v1 ', ' K2 ': ' v2 ', ' K3 ': ' V3 ', ' name ': ' Alex '}
# lis = []# for I in DIC:
# if ' K ' in I:
# lis.append (i)
# for M in Lis:
# Dic.pop (M)
# Print (DIC)
#tuple-->list list (TU) tuple (list)
#dic-->list List (DIC): All Keys---> list (Dic.keys ())
# All Values--->list (dic.values ())
# all key-value pairs (a pair of ganso in the list)--->list (dic.items ())
#set-->list List (set ())
#dict. Fromkeys (the element that precedes the split, the unique value corresponding to each element)
# dic = Dict.fromkeys (' abc ', 66)
# Print (DIC)
#False: 0, ", [], {}, ()

Two, set
#the increase of the collection#1.add#set = {' Liujj ', ' jiasp ', ' Jiaxl '}#set.add (' Cat ')#print (set)#2.update First Split and then add#set.update (' ABCDE ')#print (set)#the deletion of the collection#1.remove Delete by element#set.remove (' Jiaxl ')#print (set)#2.pop is randomly deleted and the returned value is the deleted element. #print (Set.pop ())#print (set)#3.del#4.clear Empty list: Set ()#the collection of search#only for one
collection of additions and deletions check

Iii. the relationship of the set

# the intersection of the   collection:&the set of intersection# Collections: |    The difference set of the Union # Set:-   difference# Set's inverse intersection: ^  symmetric_difference  # subset of collections: <  return value is true or false. Issubset# collection of superset: >    issuperset
orthogonal of Inverse cross subsets of the difference

Four, the depth copy

#Depth Copy#1. Assign a value. One change to the other, must be assigned first, the small data pool itself is the same memory address, so no need to assign value. #Li = [1, 2, 3]#Li2 = Li#li.append (#set2跟着set1变化)#print (LI,LI2)#2. Shallow copy. The first layer is independent, the second layer and above is the same memory address, is followed by change. #li1 = [1, 2, 3, [' Liujj ', ' jiasp ']#Li2 = li1.copy ()#li1[3].append (' Jiaxl ') #第二层增加, so the second layer in the LI2 also increases#print (LI1,LI2)#Li1.append (4)#print (LI1,LI2)#3. Deep copy,import copy/copy.deepcopy (table name). #不管第几层都是完全独立的. #Import Copy#Li2 = copy.deepcopy (li1)#Li1.append (a)#print (LI1,LI2)#li1[3].append (' xial ')#print (LI1,LI2)#4. The list of slices also belongs to-----> shallow copy.#Li2 = li1[:]#li1.append (in)#print (LI1,LI2)#li1[3].append (' lang ')#print (LI1,LI2)
Depth Copy

Python 5.7

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.