tuple和list的应用

1.list和tuple共同点和区别

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_data, 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.
    """#可以将反向标志设置为按降序排序。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Faith丶信仰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值