劉任昌python:集合set串列或清單list字典dictionary元組tuple
w3schools截圖
w3schools程式碼
#劉任昌 集合{},字典{key:value,},元組(),清單[] s= {"台積電", "鴻海", "聯發科"} t= ("台積電", "鴻海", "聯發科") list= ["台積電", "鴻海", "聯發科"] d= {2330:"台積電",2317:"鴻海",2454:"聯發科"} print("型態" + str(type(s)) + str(s)) print("型態" + str(type(t)) + str(t)) print("型態" + str(type(d)) + str(d)) print("型態" + str(type(list)) + str(list)) #字串與字串才能+所以要用str轉成字串 i = 0 for a in list: i = i+1 print("台灣第" + str(i) + "大的公司是") print(" " + a) (x,y,z) = t print("拆掉t後列出 "+ x + " " +y +" "+z) print("集合的index找出聯發科位置" + str(t.index("聯發科"))) '''大區域註解用三個引號set集合沒有順序unordered, 練習使用迴圈輸出集合內的內容。將元組分拆成變數叫做unpack'''
w3schools集合方法
Python has a set of built-in methods that you can use on sets.Method | Description |
---|---|
add() | Adds an element to the set |
clear() | Removes all the elements from the set |
copy() | Returns a copy of the set |
difference() | Returns a set containing the difference between two or more sets |
difference_update() | Removes the items in this set that are also included in another, specified set |
discard() | Remove the specified item |
intersection() | Returns a set, that is the intersection of two other sets |
intersection_update() | Removes the items in this set that are not present in other, specified set(s) |
isdisjoint() | Returns whether two sets have a intersection or not |
issubset() | Returns whether another set contains this set or not |
issuperset() | Returns whether this set contains another set or not |
pop() | Removes an element from the set |
remove() | Removes the specified element |
symmetric_difference() | Returns a set with the symmetric differences of two sets |
symmetric_difference_update() | inserts the symmetric differences from this set and another |
union() | Return a set containing the union of sets |
update() | Update the set with the union of this set and others |
w3schools清單或串列方法
Python has a set of built-in methods that you can use on lists.Method | Description |
---|---|
append() | Adds an element at the end of the list |
clear() | Removes all the elements from the list |
copy() | Returns a copy of the list |
count() | Returns the number of elements with the specified value |
extend() | Add the elements of a list (or any iterable), to the end of the current list |
index() | Returns the index of the first element with the specified value |
insert() | Adds an element at the specified position |
pop() | Removes the element at the specified position |
remove() | Removes the item with the specified value |
reverse() | Reverses the order of the list |
sort() | Sorts the list |
w3schools元組方法
Python has two built-in methods that you can use on tuples.Method | Description |
---|---|
count() | Returns the number of times a specified value occurs in a tuple |
index() | Searches the tuple for a specified value and returns the position of where it was found |
https://gracetakming.blogspot.com/2023/03/pythonsetlisttupledictionary.html
回覆刪除https://lilyhuangyuanntakming.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://sususu0123.blogspot.com/2023/03/h1background-color-purple-color-white.html
回覆刪除https://sarahyu-programming.blogspot.com/2023/03/h1background-color-purple-color-white.html
回覆刪除https://elainehaung0812.blogspot.com/2023/03/pythonsetlistdictionary.html
回覆刪除https://gary20010101.blogspot.com/2023/03/w3schools-w3schools-settuple-list.html
回覆刪除https://xiao920727.blogspot.com/2023/03/w3schools-w3schools-settuple-list.html
回覆刪除https://mandytakming.blogspot.com/2023/03/pythonsetlisttupledictionary.html
回覆刪除作者已經移除這則留言。
回覆刪除https://kai1115.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://jennysuwanting.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://leitrezesig.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://kinzac.blogspot.com/2023/03/blog-post.html
回覆刪除https://takmingyiching.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://ericlian-pc.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://sherryd11117110.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://www.blogger.com/blog/post/edit/preview/2897209240624336373/7491712799294218002
回覆刪除https://chen-ping0330.blogspot.com/2023/03/pythonsetlistdictionarytuple.html\
回覆刪除https://www.blogger.com/blog/post/edit/preview/2128794278855587960/7366486500598636253
回覆刪除https://11117102.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://hosidesu.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://d11117235catian.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://sophie0930307.blogspot.com/2023/03/pythonsetlistdictionarytuple.html
回覆刪除https://cathyleerou.blogspot.com/2023/03/w3schools-w3schools-keyvalue-s-t-list-d.html
回覆刪除