[python]リスト、チュートリアル、三、ディックショーナーを整理する
8871 ワード
Python Collections
List
:要素が順番に並んでいるSet
:元素無秩序配列Tuple
:リストと比較して要素値を変更できない特徴があるDictionary
:key-valueペアからなり、順番なしList
# list 라는 메소드를 통해서 만든 예시
thislist = list(("apple", "banana", "cherry"))
# 이렇게 할당을 통해 만들 수도 있음
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
# 서로 다른 타입의 데이터가 올 수 있다.
thislist = [1, 2, "apple", True, False]
リストには、次の方法が組み込まれています.MethodDescriptionappend()Adds an element at the end of the listclear()Removes all the elements from the listcopy()Returns a copy of the listcount()Returns the number of elements with the specified valueextend()Add the elements of a list (or any iterable), to the end of the current listindex()Returns the index of the first element with the specified valueinsert()Adds an element at the specified positionpop()Removes the element at the specified positionremove()Removes the first item with the specified valuereverse()Reverses the order of the listsort()Sorts the list
Tuple
thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
tupleで使用できる組み込み方法は次のとおりです.MethodDescriptioncount()Returns the number of times a specified value occurs in a tupleindex()Searches the tuple for a specified value and returns the position of where it was found
Set
# 할당을 통해서 만들 수 있다.
thisset = {"apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"}
# 생성자를 통해서도 만들 수 있다.
thisset = set(("apple","banana","cherry"))
3つの組み込み方法は次のとおりです.MethodDescriptionadd()Adds an element to the setclear()Removes all the elements from the setcopy()Returns a copy of the setdifference()Returns a set containing the difference between two or more setsdifference_update()Removes the items in this set that are also included in another, specified setdiscard()Remove the specified itemintersection()Returns a set, that is the intersection of two or more setsintersection_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 notissubset()Returns whether another set contains this set or notissuperset()Returns whether this set contains another set or notpop()Removes an element from the setremove()Removes the specified elementsymmetric_difference()Returns a set with the symmetric differences of two setssymmetric_difference_update()inserts the symmetric differences from this set and anotherunion()Return a set containing the union of setsupdate()Update the set with another set, or any other iterable
Dictionary
# 생성자를 이용하여 생성할 수 있다.
thisdict = dict(brand = "Ford", model = "Mustang", year = 1964)
#할당을 통해서도 생성할 수 있다.
thisdict = {"brand": "Ford", "model": "Mustang", "year": 1964}
ディックシャーナ社が提供する組み込み方法は以下の通りです.MethodDescriptionclear()Removes all the elements from the dictionarycopy()Returns a copy of the dictionaryfromkeys()Returns a dictionary with the specified keys and valueget()Returns the value of the specified keyitems()Returns a list containing a tuple for each key value pairkeys()Returns a list containing the dictionary's keyspop()Removes the element with the specified keypopitem()Removes the last inserted key-value pairsetdefault()Returns the value of the specified key. If the key does not exist: insert the key, with the specified valueupdate()Updates the dictionary with the specified key-value pairsvalues()Returns a list of all the values in the dictionary
ソース
Reference
この問題について([python]リスト、チュートリアル、三、ディックショーナーを整理する), 我々は、より多くの情報をここで見つけました https://velog.io/@limsw/Python-리스트-튜플-셋-딕셔너리-정리하기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol