map(function, iterable, …):
会根据提供的函数对指定序列做映射。
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。
# python3.9.10
# -*- codeing = utf-8 -*-
# @Time :2022/3/4 9:06
# @Author : 刘念卿
# @File : test.py
# @Software : PyCharm
# 使用list把map对象转化为列表,
# 不使用的话会输出: <map object at 0x000002624EEC0640>
# lamba为匿名函数
a = list(map(lambda x: x+1, [1,2,3,4,5]))
print(a)
def function(x,y):
return x + y
# 使用一个函数,这里为function,不是function(),需注意
b = list(map(function, [1,2,3,4,5],[1,2,3,4,5]))
print(b)
find():
用于查找字符串,会返回匹配到的第一个的下表,未匹配到返回-1
s1 = 'asffasdfgbvcxsdf'
s2 = 'asdg'
s3 = 'df'
# find()会返回匹配到的第一个的下表,未匹配到返回-1
print(s1.find(s2))
print(s1.find(s3))