如何删除字符串的左侧部分?

发布于 2021-01-29 15:04:08

我有一些简单的python代码,可在文件中搜索字符串,例如path=c:\path,其中c:\path部分可能会有所不同。当前代码是:

def find_path(i_file):
    lines = open(i_file).readlines()
    for line in lines:
        if line.startswith("Path="):
            return # what to do here in order to get line content after "Path=" ?

什么是获取文字的简单方法Path=

关注者
0
被浏览
85
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    从开始Python 3.9,您可以使用removeprefix

    'Path=helloworld'.removeprefix('Path=')
    # 'helloworld'
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看