python中判定字符串是否以指定字符結尾或以指定字符開頭


 

1、

>>> a = "good"
>>> a 'good'
>>> a.startswith("g") ## 判斷字符串是否以g開頭 True >>> a.startswith("o") ## 判斷是否以o開頭 False >>> a.startswith("d") False >>> a.endswith("g") ## 判斷字符串是否以g結尾 False >>> a.endswith("o") False >>> a.endswith("d") ## 判斷字符串是否以d結尾 True >>> a.startswith("g",0,4) ## 指定判斷字符串的范圍 True >>> a.startswith("g",1,4) False >>> a.startswith("o",1,4) True >>> a.endswith("d",0,4) True >>> a.endswith("d",0,3) False >>> a.endswith("o",0,3) True

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM