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 FalseTrue False
以上がPython のプレフィックスとサフィックスの操作の詳細な説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。