Python 判断字符串开头和

By | May 1, 2020

Python判断字符串是否以某个字符开头:

判断字符串site = ‘https://www.houyunbo.com’是否以http开头

site.startswith(‘http’)                      //True

startswith 多个参数放入元组,满足其中一个就是True    site.startswith((‘ftp’,’http’))      //True

site[:4] ==’http’                              //True

 

Python判断字符串是否以某个字符结尾

判断字符串site = ‘https://www.houyunbo.com’是否以 .jpg结尾

site.endswith(‘.jpg’)                //True

startswith 多个参数放入元组,满足其中一个就是True    site.startswith((‘.jpg’,’.gif’))      //True

site[-4:] ==’.jpg’                              //True

 

Leave a Reply