3、列表、字典、元组操作
1、列表:
strList=['']:列表的创建。
str='字符串'
newStr='新的字符串'。
strList.append:进行列表数据信息的添加操作。
strList[0]=newStr:根据下标,进行列表指定元素数据信息的修改操作
str in strLsit:返回boolen类型,指定字符串信息是否在列表中存在。
for item in strList:进行列表数据的遍历操作,item为元素值
del strList[0]:根据列表下标,删除指定的列表元素。
strList.pop():删除列表最后一个元素的数据信息。
strList.remove('元素的值'):根据元素的值进行删除操作。
7、filter:函数
1、help(filter):
filter(...)
filter(function or None, sequence) -> list, tuple, or string
Return those items of sequence for which function(item) is true. If
function is None, return the items that are true. If sequence is a tuple
or string, return the same type, else return a list.
2、参数分析:
1、function:接受一个参数,返回布尔值True或False
2、sequence:序列可以是str,tuple,list
3、语法
filter函数会对序列参数sequence中的每个元素调用function函数,最后返回的结果包含调用结果为True的元素。返回值的类型和参数sequence的类型相同
4、示例
filter(lambda x: x%2, [1, 2, 3, 4])
[1, 3]
filter(None, "she")
'she'
8、reduce:函数
1、help(reduce):
reduce(...)
reduce(function, sequence[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.
2、参数分析:
1、function:该函数有两个参数
2、sequence:序列可以是str,tuple,list
3、initial:固定初始值
4、threading模块中定义了Lock()类,可以方便的处理锁定。
mutex=threading.Lock():互斥锁对象的创建。
if mutex.acquire([blocking]):进行锁定,锁定成功后返回true;锁定方法acquire()可以有一个blocking参数。如果设定blocking为True,则当前线程会堵塞,直到获取到这个锁为止(如果没有指定,那么默认为True);如果设定blocking为False,则当前线程不会堵塞。
mutex.release():执行完程序内容后进行锁的释放操作。