![](/img/trans.png)
[英]'if' and 'if not' in python, looping to search for a particular substring in a text file. what's the difference between the two? when to use which?
[英]Difference between two string as substring in python
我有兩個文件路徑作為字符串
string1 = r"C:\Users\Admin"
string2= "C:\Users\Admin\Context1\Context2\filepath.dat"
我怎樣才能得到作為“ Context1\\Context2\\filepath.dat
”的區別
到目前為止,我正在按字符迭代string1,並在失敗時與string2比較,我正在返回string2[index:]
應該有一些更簡單的pythonic方法來做到這一點。 或指向我的文檔。 請在python中將我視為新手。 任何幫助深表感謝
同樣在我的情況下,string1始終是string2的祖先根
string2[len(string1)+1:]
就像用string2中的空字符串替換string1一樣簡單
string2.replace(string1,"")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.