python str.replace / str.endswith 以及 python语句(返回目录中所有JPG图像的文件名列表)
来源:互联网 发布:下载八爪鱼大数据 编辑:程序博客网 时间:2024/05/16 02:59
help(str.replace)
参数old:字符串S中的子字符串
参数new:用来替换old的新字符串
参数count:可选,如果指定count(整数),且该count数量小于old在S中的个数,则old会被new替换count次
string="asdffdsaasdffdsaasdf"old="as"new="12"string.replace(old, new)
################################################
str.endswith函数
help(str.endswith)
参数说明:
suffix:指定的后缀名,用于判断字符串S的后缀是否和其相同;suffix也可以使用一个字符串元组以进行多个比对
start:可选,用于字符串S在下标start开始
end:可选,停止比较S在下表end
判断S是否为jpg文件:
S="result.jpg"S.endswith('.jpg')str=('.jpg','.pgm','.bmp','.jpeg')S.endswith(str)
从start=7开始,此时S[start]='j'
从end=8结束,此时S[end]='p'
##################################################
返回目录中所有JPG图像的文件名列表
(python 语句)
import ospath=os.getcwd() #获取当前目录路径[os.path.join(path, f) for f in os.listdir(path) if f.endwith('.jpg')]
0 0
- python str.replace / str.endswith 以及 python语句(返回目录中所有JPG图像的文件名列表)
- python 中 str 拾遗
- python 的repr和str以及“”
- Python的str类
- Python str
- python-str()
- python 中 str() 与 repr() 的区别
- python中repr和 str的异同
- python中str()与repr()的区别
- Python中str操作的学习
- python中字符串str的strip()方法
- Python中Str类的常用方法
- python中字符串str的strip()方法
- Python中str的format()方法
- python 将元组,列表中int 类型转为str
- python中获取指定目录下所有文件名列表的程序
- python中获取指定目录下所有文件名列表的程序
- python中从str中提取元素到list以及将list转换为str
- Xutil 中BitmapUtils的全面注释
- sql语法练习(二)
- 高通平台启动流程
- 进制转换之原理实现(Java)
- openstack网络(neutron)模式之GRE的基本原理
- python str.replace / str.endswith 以及 python语句(返回目录中所有JPG图像的文件名列表)
- web项目 maven下 使用servlet调用 mysql数据库
- sql语法练习(三)
- 电商搜索之动态属性值(特征值)聚合
- 漫谈 HMM之二:Forward-Backward Algorithm
- VC使用WMI获取活动的网卡列表
- CSS 框模型Margin ,Border ,Padding ,Content
- hdu 1427 速算24点
- easyui combobox 下拉列表添加选择项