程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python----four built-in data structures (dict, list, tuple, set)

編輯:Python

1, dict

Unordered, can be changed

2. tuple

Ordered, unchangeable

3, list

Orderly, can be changed (add, delete)

4, set

Disordered, may change

{element 1, element 2, element 3.....} are defined with curly brackets like the dictionary, but the difference is that there is no colon separation, there is another definitionThe method is to pass any sequence to the set() function (such as a string set('fsdaf'))

Operation of 2 sets:

The set in python is the same as the set in mathematics. It also has intersection, union, difference and other operations. The union provides the method union(), the difference method difference(), but the difference here is different.It is only possible to display all elements in the collection using this method that are different from another collection, and the method intersection() of the intersection displays the same elements

The following code is used to implement the above method:

#Set operation
temp={'a','e','i','o','u'}
temp2=set("fda");

#Intersection operation
result=temp.intersection(temp2)#{'a'}

#Parallel operation
result=temp.union(temp2)#{'a', 'o', 'f', 'd', 'u', 'e', ​​'i'}

#Difference operation
result=temp.difference(temp2)#{'o', 'e', ​​'u', 'i'}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

1. Author:​ ​Syw​​

3. The copyright of this article belongs to the author, welcome to reprint, butWithout the consent of the author, this statement must be retained, and the original text link should be given in an obvious position on the article page, otherwise the right to pursue legal responsibility is reserved.

4. If there are any mistakes in the text, please point them out.lest more people be misled.





  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved