pythonメタグループにネストされたメタグループ_Pythonのメタグループ


pythonメタグループにネストされたメタグループ
Pythonユニット(Python Tuples)
Tuples in Python are a collection of elements in a round bracket() or not but separated by commas. Tuples are similar to list in some operations like indexing, concatenation, etc. but lists are mutable whereas tuples are immutable acts like a string. In Python, Tuples are converted into lists by using the keyword list and list are converted into tuples by using keyword "tuple".
Pythonのメタグループは、カッコ()の要素の集合ではなく、カンマで区切られています.メタグループは、インデックス、接続などのいくつかの操作でリストに似ていますが、リストは可変であり、メタグループは文字列などの可変な動作です.Pythonでは、キーワードリストを使用してメタグループをリストに変換し、キーワード「tuple」を使用してリストをメタグループに変換します.
Here we will see some examples to understand how to create tuples?, convert lists into tuples?, concatenation of tuples, nested tuples, etc.
ここでは、メタグループの作成方法について説明する例を示します.リストをメタグループに変換しますか?メタグループの直列、ネストされたメタグループなど.
メタグループの作成(Creating Tuples)t='Python','Tuple','Lists' t2=('Python','Tuple','Lists','Includehelp','best') e_t=() u_l_t=('includehelp',) print('empty tuple:',e_t) print('Unit length tuple:',u_l_t) print('first tuple:',t) print('Second tuple:',t2) Note: When you are going to create a tuple of length 1 in Python then you must put a comma after the element before closing the round brackets.
注意:Pythonで長さ1のメタグループを作成する場合は、要素の後にカンマを付けてカッコを閉じる必要があります.
Output
しゅつりょくりょうempty tuple: () Unit length tuple: ('includehelp',) first tuple: ('Python', 'Tuple', 'Lists') Second tuple: ('Python', 'Tuple', 'Lists', 'Includehelp', 'best') Here, we have seen that if we are creating tuples with round brackets or not both results are the same.
ここでは、カッコ付きのメタグループを作成する場合、両方の結果が異なります.
タプルの直列(Concatenation of Tuples)
We can simply add tuples like lists by using plus (+) sign between it. Let's suppose the same tuples that we have created just above and try to add these tuples.
これらの間にプラス記号(+)を使用することで、類似リストのメタグループを簡単に追加できます.同じメタグループを作成し、追加しようとしたとします.
Program:
プログラム:t = 'Python','Tuple','Lists' t2 = ('Python','Tuple','Lists','Includehelp','best') print('Concatenation of Tuples:
',t+t2)
Output
しゅつりょくりょうConcatenation of Tuples: ('Python', 'Tuple', 'Lists', 'Python', 'Tuple', 'Lists', 'Includehelp', 'best') リストをタプルに変換し、タプルをリストに変換します(Convert list into tuples and tuples into list)t=('Python','Tuple','Lists','Includehelp','best') l=list(t) #now l is list. t2=tuple(l) #Here list is converted into tuple. print('tuple is converted into list:',t) print('list is converted into tuple:',t2) Output
しゅつりょくりょうtuple is converted into list: ['Python', 'Tuple', 'Lists', 'Includehelp', 'best'] list is converted into tuple: ('Python','Tuple','Lists','Includehelp','best') ネストされたメタグループ(Nested tuples)
Nested tuples means one tuple inside another like nested lists. To create a nested tuple, we have to simply put both or more tuples in the round brackets separated with commas. Again we will assume the same tuple that we have created above and try to make it in the form of a nested tuple. Let's look at the program,
ネストされたメタグループとは、ネストされたリストのような別のネストされた内部のメタグループを指します.ネストされたメタグループを作成するには、カンマで区切られたカッコに2つ以上のメタグループを配置するだけです.同様に、上記と同じメタグループを想定し、ネストされたメタグループとして作成してみます.プログラムを見てみましょうt='Python','Tuple','Lists' t2=('Python','Tuple','Lists','Includehelp','best') nested_t=(t,t2) print('Nested tuple:',nested_t) Output
しゅつりょくりょうNested tuple: (('Python', 'Tuple', 'Lists'), ('Python', 'Tuple', 'Lists', 'Includehelp', 'best')) 翻訳:https://www.includehelp.com/python/tuples.aspx
pythonメタグループにネストされたメタグループ