要检测python字符串是否以特定子字符串结尾,比如说".txt",有一个方便的内置python字符串方法;
if file_string.endswith(".txt"):
Run Code Online (Sandbox Code Playgroud)
我想检测一个python字符串是否以特定的子字符串开头"begin_like_this".我找不到一个方便的方法,我可以像这样使用;
if file_string.beginswith("begin_like_this"):
Run Code Online (Sandbox Code Playgroud)
我使用的是python v3.6
Pat*_*ugh 33
您正在寻找 str.startswith
if file_string.startswith("begin_like_this"):
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13153 次 |
| 最近记录: |