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

Tuples in Python

編輯:Python

1.tuple introduction

tuple is another ordered list, also known as "tuple".If a tuple is used to represent the names of the classmates in the class, the tuple is used to represent the following:

t = ('Zhang San', 'Li Si', 'Wang Wu')

tuple is very similar to list, the only difference between creating a tuple and creating a list is that () is used instead of [], tuple cannot be changed after it is createdWell, tuple has no methods for inserting and removing elements.

The method of obtaining tuple elements is exactly the same as that of list. We can normally use t[0], t[-1] and other index methods to access elements, but cannot assign them to other elements.

2. Create a single-element tuple

tuple can contain 0, 1 and any number of elements, tuple containing multiple elements has been created in the above example.

A tuple of 0 elements is an empty tuple, which is directly represented by ():

t = ()print(t)

Execute the above code, the output result is:

()


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