python中关于前后缀操作的详解
程序员文章站
2023-12-23 08:05:22
...
返回后缀名
import os path = 'first_directory/second_directory/file.txt'print os.path.splitext(path)[1]print type(os.path.splitext(path)[1])
.txt <type 'str'>
前缀名的bool判断
path = 'first_directory/second_directory/file.txt'print path.startswith('fir')
True
后缀名的bool判断
path = 'first_directory/second_directory/file.txt'print path.endswith('.txt')
True
os.path.splitext、.startswith、.startswith 探究
import os path = 'first_directory/second_directory/file.txt'print os.path.splitext(path)print os.path.splitext(path)[1]print type(os.path.splitext(path)[1])printprint path.startswith('fir')print path.startswith('aaa')print type(path.startswith('fir'))printprint path.endswith('.txt')print path.endswith('.aaa')print type(path.endswith('.txt'))
('first_directory/second_directory/file', '.txt') .txt <type 'str'> True False <type 'bool'> True False <type 'bool'>
以上就是python中关于前后缀操作的详解的详细内容,更多请关注其它相关文章!