1、list和tuple的共同点:都可以容纳多种数据类型
不同点:list是可更改的,但是tuple是不可更改的
2、定义一个变量,包含现在所学的数据类型
list_data = [1, 1.1, 1+2j, b'123456', (6, 6, 6), '6', True, None, [6, 6, 6]]
print(list_data)
print(type(list_data))
输出结果
[1, 1.1, (1+2j), b'123456', (6, 6, 6), '6', True, None, [6, 6, 6]]
<class 'list'>
3、目前学到的序列有哪些?
字符串str;字节bytes;元组tuple;列表list
将除了tuple之外的序列转换为tuple
list_data = [1]
tuple_data = tuple(list_data)
print(tuple_data)
输出结果
(1, )
将除了list之外的序列转换为list
bytes_data = b'123'
str_data = '123'
tuple_data = (1, 2, 3)
list_data = [str_data, bytes_dara, tuple_data]
print(list_data)
输出结果
['123', b'123', (1, 2, 3)]
4、tuple中有哪些操作方法
count(self, *args, **kwargs): # real signature unknown
""" Return number of occurrences of value. """
#统计出现的次数
def index(self, *args, **kwargs): # real signature unknown
"""
Return first index of value.
#返回第一个的索引(索引:从0开始)
5.list中有哪些操作方法、
append(self, *args, **kwargs): # real signature unknown
""" Append object to the end of the list. """
#将对象追加到列表的末尾
def clear(self, *args, **kwargs): # real signature unknown
""" Remove all items from list. """
#从列表中删除所有项目
def copy(self, *args, **kwargs): # real signature unknown
""" Return a shallow copy of the list. """
#返回值的出现次数
def count(self, *args, **kwargs): # real signature unknown
""" Return number of occurrences of value. """
#通过从可迭代对象追加元素来扩展列表
def extend(self, *args, **kwargs): # real signature unknown
""" Extend list by appending elements from the iterable. """
pass
def index(self, *args, **kwargs): # real signature unknown
"""
Return first index of value.
#返回值的第一个索引
Raises ValueError if the value is not present.
"""
#如果值不存在,则提高值错误
def insert(self, *args, **kwargs): # real signature unknown
""" Insert object before index. """
#在索引之前插入对象。
def pop(self, *args, **kwargs): # real signature unknown
"""
Remove and return item at index (default last).
#删除并返回索引处的项目(默认在后面)
Raises IndexError if list is empty or index is out of range.
"""
#如果列表为空或索引超出范围,则引发索引错误
def remove(self, *args, **kwargs): # real signature unknown
"""
Remove first occurrence of value.
#删除第一个出现的值
Raises ValueError if the value is not present.
"""
#如果值不存在,则提高值错误
def reverse(self, *args, **kwargs): # real signature unknown
""" Reverse *IN PLACE*. """
#反向
def sort(self, *args, **kwargs): # real signature unknown
"""
Sort the list in ascending order and return None.
#按升序对列表进行排序,并返回 None
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
order of two equal elements is maintained).
#排序是就地的(即列表本身被修改)和稳定的(即保持两个相等元素的顺序)
If a key function is given, apply it once to each list item and sort them,
ascending or descending, according to their function values.
#如果给出了一个关键功能,则将其应用于每个列表项一次并对其进行排序,
升序或降序,根据其函数值。
The reverse flag can be set to sort in descending order.
"""#可以将反向标志设置为按降序排序。