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'>
path = 'first_directory/second_directory/file.txt'print path.startswith('fir')
True
path = 'first_directory/second_directory/file.txt'print path.endswith('.txt')
True
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中关于前后缀操作的详解的详细内容,更多请关注php中文网其它相关文章!
已抢64986个
抢已抢27432个
抢已抢14931个
抢已抢7430个
抢已抢9393个
抢已抢18981个
抢