![打印单词从python中的特定字母开始?[关闭],第1张 打印单词从python中的特定字母开始?[关闭],第1张](/aiimages/%E6%89%93%E5%8D%B0%E5%8D%95%E8%AF%8D%E4%BB%8Epython%E4%B8%AD%E7%9A%84%E7%89%B9%E5%AE%9A%E5%AD%97%E6%AF%8D%E5%BC%80%E5%A7%8B%EF%BC%9F%5B%E5%85%B3%E9%97%AD%5D.png)
采用
str.startswith
例如:
St= "where is my mobile"for i in St.split(): if i.startswith("m"): print(i)输出:
mymobile
使用
filter
例如:
L = ['mobile',"pencil","Pen","eraser","Book"]print( list(filter(lambda x: x.lower().startswith("p"), L)) )输出:
['pencil', 'Pen']
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)