[python]リスト、チュートリアル、三、ディックショーナーを整理する


Python Collections

  • 存在4種
  • リスト、チュートリアル、3種、ディックシェリー書・
  • List:要素が順番に並んでいる
  • Set:元素無秩序配列
  • インデックスにアクセスできない
  • Tuple:リストと比較して要素値を変更できない特徴がある
  • Dictionary:key-valueペアからなり、順番なし
  • キー値を基準としたインデックスですから.
  • List

  • Constructorで生成できます.
  • 異なるタイプのデータを含んでもよい.
  • 可変と順序の特徴がある.
  • # 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

  • 括弧で作成できます.
  • count()、index()メソッドのみ使用できます.
  • インデックスアクセス可能
  • データ変更不可
  • thistuple[0]=「瓜」はこのように変えられない.
  • 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

  • Keyは重複が許されない資料型です.
  • .keys(), .values(), .itmes()コマンドを使用して、有用なパーティションを作成できます.
  • 可変の特徴を有する.
  • # 생성자를 이용하여 생성할 수 있다.
    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

    ソース

  • https://www.w3schools.com/