一.基本数据类型
整数:int
字符串:str(注:\t等于一个tab键)
布尔值: bool
列表:list
列表用[]
元祖:tuple
元祖用()
字典:dict
注:所有的数据类型都存在想对应的类列里,元祖和列表功能一样,列表可以修改,元祖不能修改。
二.列表所有数据类型:
基本操作:
- 索引
- 切片
- 长度
- 包含
- 循环
class tuple(object):"""tuple() -> empty tupletuple(iterable) -> tuple initialized from iterable's itemsIf the argument is a tuple, the return value is the same object."""def count(self, value): # real signature unknown; restored from __doc__""" T.count(value) -> integer -- return number of occurrences of value """(T.count(价值)- >整数,返回值的出现次数)return 0def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__"""T.index(value, [start, [stop]]) -> integer -- return first index of value.Raises ValueError if the value is not present."""(T。指数(价值,[开始,[不要]])- >整数,返回第一索引值。提出了ValueError如果不存在的价值。)return 0def __add__(self, *args, **kwargs): # real signature unknown""" Return self+value. """passdef __contains__(self, *args, **kwargs): # real signature unknown""" Return key in self. """passdef __eq__(self, *args, **kwargs): # real signature unknown""" Return self==value. """passdef __getattribute__(self, *args, **kwargs): # real signature unknown""" Return getattr(self, name). """passdef __getitem__(self, *args, **kwargs): # real signature unknown""" Return self[key]. """passdef __getnewargs__(self, *args, **kwargs): # real signature unknownpassdef __ge__(self, *args, **kwargs): # real signature unknown""" Return self>=value. """passdef __gt__(self, *args, **kwargs): # real signature unknown""" Return self>value. """passdef __hash__(self, *args, **kwargs): # real signature unknown""" Return hash(self). """passdef __init__(self, seq=()): # known special case of tuple.__init__"""tuple() -> empty tupletuple(iterable) -> tuple initialized from iterable's itemsIf the argument is a tuple, the return value is the same object.# (copied from class doc)"""passdef __iter__(self, *args, **kwargs): # real signature unknown""" Implement iter(self). """passdef __len__(self, *args, **kwargs): # real signature unknown""" Return len(self). """passdef __le__(self, *args, **kwargs): # real signature unknown""" Return self<=value. """passdef __lt__(self, *args, **kwargs): # real signature unknown""" Return self<value. """passdef __mul__(self, *args, **kwargs): # real signature unknown""" Return self*value.n """pass@staticmethod # known case of __new__def __new__(*args, **kwargs): # real signature unknown""" Create and return a new object. See help(type) for accurate signature. """passdef __ne__(self, *args, **kwargs): # real signature unknown""" Return self!=value. """passdef __repr__(self, *args, **kwargs): # real signature unknown""" Return repr(self). """passdef __rmul__(self, *args, **kwargs): # real signature unknown""" Return self*value. """pass
三.所有元祖数据类型举例
#count 用于计算元素出现的个数
name_tuple = ("zhangyanlin","suoning","nick")
print(name_tuple.count('zhangyanlin'))#index获取指定元素的指定位置
name_tuple = ("zhangyanlin","suoning","nick")
print(name_tuple.index('zhangyanlin'))
四.索引
name_tuple = ("zhangyanlin","suoning","nick")
print(name_tuple[1])
五.切片
#取出第一位到最后一位减1的元素
name_tuple = ("zhangyanlin","suoning","nick")
print(name_tuple[0:len(name_tuple)-1])
六.总长度len
#取出最后一位减1的元素
name_tuple = ("zhangyanlin","suoning","nick")
print(name_tuple[len(name_tuple)-1])
七.for循环
name_tuple = ("zhangyanlin","suoning","nick")
for i in name_tuple:print(i)