当前位置:网站首页>Basic knowledge of tuples

Basic knowledge of tuples

2022-07-05 03:17:00 Programming is too difficult

Definition of tuple

Tuples :tuple
 Insert picture description here
If you want to create an empty tuple , Don't write anything in brackets .
If there is only one data in the tuple , Then remember to add a comma .
If there is more than one data in the tuple , Data are separated by commas , There is no need to add a comma after the last data .

Access to tuple elements

Access to elements in tuples and list equally , Can be accessed by subscript .
Fill in brackets with -1 Indicates access to the last data ,list The same in China .
list And tuples can be sliced . Write... In brackets [ Start subscript : Terminate subscript ( But does not contain ): Step value ].

 Insert picture description here

Basic operations on tuples

increase

 Insert picture description here
You can connect two tuples with a plus sign , Open up a space to store the content after the connection .

Delete

 Insert picture description here
use del After deleting tuples , The entire variable will be deleted , An error will be reported when using this variable next time , Indicates that this variable has not been defined .

modify

 Insert picture description here
Data in tuples cannot be modified , however list Data that can be used as tuples ,list The data in can be modified .

lookup

The search operation is to traverse the data in tuples , By subscript operation .

Other operating

Tuples can also be like list Same count ,tup.count()
To turn a variable into a tuple , Write the variable name directly in tuple() In parentheses .

原网站

版权声明
本文为[Programming is too difficult]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140756096387.html