Python基本数据类型(元组)
2020-12-13 02:22
标签:add name eal item rabl 用法 基本 img 创建 基本数据类型 四、元组 元组(Tuple)是一种与列表类似的序列类型。元组的基本用法与列表十分类似。只不过元组一旦创建,就不能改变,因此,元组可以看成是一种不可变的列表。 1.元组格式 Python用一对括号“()”生成元组,中间的元素用逗号“,”隔开。尽量在最后元素后面加上一个额外的逗号“,”加以区分括号与元组,特别是只含单元素的元组: 2.元组与列表的相互转换 列表和元组可以使用tuple()函数和list()函数相互转换: 3.索引和切片 对于元组来说,只能通过索引和切片来取值,不能进行修改操作。 4.元组的方法 由于元组是不可变的,所有它只支持.count()方法和.index()方法,用法与列表一致: .count()方法是计算元组的指定元素出现的次数。 .index()方法是获取指定元素第一次出现的索引位置。 元组所有方法归纳: Python基本数据类型(元组) 标签:add name eal item rabl 用法 基本 img 创建 原文地址:https://www.cnblogs.com/lzc69/p/11032553.htmltu = (11,22,"alex",[(33,44)],)
li = [3,6,1,5,4,6]
print(tuple(li)) #结果为:(3, 6, 1, 5, 4, 6)
tu = (11,22,"alex",[(33,44)],)
print(list(tu)) #结果为:[11, 22, ‘alex‘, [(33, 44)]]
tu = (11,22,"alex",[(33,44)],)
print(tu[3][0][1]) #结果为:44
print(tu[1:-1]) #结果为:(22, ‘alex‘)
tu = (11,22,"alex",[(33,44)],22,)
print(tu.count(22)) #结果为:2
tu = (11,22,"alex",[(33,44)],22,)
print(tu.index(22)) #结果为:1
1 lass tuple(object):
2 """
3 tuple() -> empty tuple
4 tuple(iterable) -> tuple initialized from iterable‘s items
5
6 If the argument is a tuple, the return value is the same object.
7 """
8 def count(self, value): # real signature unknown; restored from __doc__
9 """ T.count(value) -> integer -- return number of occurrences of value """
10 return 0
11
12 def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
13 """
14 T.index(value, [start, [stop]]) -> integer -- return first index of value.
15 Raises ValueError if the value is not present.
16 """
17 return 0
18
19 def __add__(self, y): # real signature unknown; restored from __doc__
20 """ x.__add__(y) x+y """
21 pass
22
23 def __contains__(self, y): # real signature unknown; restored from __doc__
24 """ x.__contains__(y) y in x """
25 pass
26
27 def __eq__(self, y): # real signature unknown; restored from __doc__
28 """ x.__eq__(y) x==y """
29 pass
30
31 def __getattribute__(self, name): # real signature unknown; restored from __doc__
32 """ x.__getattribute__(‘name‘) x.name """
33 pass
34
35 def __getitem__(self, y): # real signature unknown; restored from __doc__
36 """ x.__getitem__(y) x[y] """
37 pass
38
39 def __getnewargs__(self, *args, **kwargs): # real signature unknown
40 pass
41
42 def __getslice__(self, i, j): # real signature unknown; restored from __doc__
43 """
44 x.__getslice__(i, j) x[i:j]
45
46 Use of negative indices is not supported.
47 """
48 pass
49
50 def __ge__(self, y): # real signature unknown; restored from __doc__
51 """ x.__ge__(y) x>=y """
52 pass
53
54 def __gt__(self, y): # real signature unknown; restored from __doc__
55 """ x.__gt__(y) x>y """
56 pass
57
58 def __hash__(self): # real signature unknown; restored from __doc__
59 """ x.__hash__() hash(x) """
60 pass
61
62 def __init__(self, seq=()): # known special case of tuple.__init__
63 """
64 tuple() -> empty tuple
65 tuple(iterable) -> tuple initialized from iterable‘s items
66
67 If the argument is a tuple, the return value is the same object.
68 # (copied from class doc)
69 """
70 pass
71
72 def __iter__(self): # real signature unknown; restored from __doc__
73 """ x.__iter__() iter(x) """
74 pass
75
76 def __len__(self): # real signature unknown; restored from __doc__
77 """ x.__len__() len(x) """
78 pass
79
80 def __le__(self, y): # real signature unknown; restored from __doc__
81 """ x.__le__(y) x"""
82 pass
83
84 def __lt__(self, y): # real signature unknown; restored from __doc__
85 """ x.__lt__(y) x
上一篇:windows另类执行exp提权
下一篇:JSP简介