先来总结下数据类型
数字、字符串、布尔型、列表、元组、字典、集合
可变数据类型:列表、字典、集合 --所谓可变就是可以被修改,且修改后在内存中id不变
不可变数据类型:字符串、元组、数字
有序:字符串、列表、元组
**获取元素的方法包括:索引、切片、for循环
无序:字典、集合
其中数字是直接获取。
下面是关于列表的常用方法(list):
def append(self, p_object): # real signature unknown; restored from __doc__
--在列表中新增元素,只能增加一个元素,且放在最后的位置。
""" L.append(object) -> None -- append object to end """
pass
def clear(self): # real signature unknown; restored from __doc__
--清空列表
""" L.clear() -> None -- remove all items from L """
pass
def copy(self): # real signature unknown; restored from __doc__
--复制一个列表,浅拷贝
""" L.copy() -> list -- a shallow copy of L """
return []
def count(self, value): # real signature unknown; restored from __doc__
--计算元素在列表中存在的个数,比如:
li = [1,2,3,2]
print(li.count(2)) 输出:2
""" L.count(value) -> integer -- return number of occurrences of value """
return 0
def extend(self, iterable): # real signature unknown; restored from __doc__
--扩展列表,传一个参数,可以是字符串,也可以是列表、元组、字典,但不可以是数字。
""" L.extend(iterable) -> None -- extend list by appending elements from the iterable """
pass
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
--根据元素的值查找该元素的索引
"""
L.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
"""
return 0
def insert(self, index, p_object): # real signature unknown; restored from __doc__
--在某个索引前添加一个元素
""" L.insert(index, object) -- insert object before index """
pass
def pop(self, index=None): # real signature unknown; restored from __doc__
--删除列表中的元素,默认删除最后一个
"""
L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
"""
pass
def remove(self, value): # real signature unknown; restored from __doc__
--删除某个指定元素
"""
L.remove(value) -> None -- remove first occurrence of value.
Raises ValueError if the value is not present.
"""
pass
def reverse(self): # real signature unknown; restored from __doc__
--列表顺序取反
""" L.reverse() -- reverse *IN PLACE* """
pass
def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__
--给列表排序
""" L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
pass
标签:基本,__,--,unknown,数据类型,value,列表,signature,def
From: https://www.cnblogs.com/kkbest/p/18264325