#chp15.常用文字字串函數 #範例15-2:查詢文字內是否有某個字串 #https://www.w3schools.com/python/python_strings.asp #https://www.w3school.com.cn/python/python_strings.asp #https://www.runoob.com/python3/python3-string.html #1.----- 查詢某個字串是否在文字內?: if txt in a1 --------- a1 = "tom, john, mike, jolin" txt = "tom" #2.----- 查詢某個字串是否在文字內?: txt in a1 --------- a1 = "tom, john, mike, jolin" txt = "tom" #3.----- 查詢某個字串是否不在文字內? if txt not in a1 --------- a1 = "tom, john, mike, jolin" txt = "peter" #4.----- 文字的連接: + --------- a1 = "john" a2 = "0922111333" #------------------------------------------------------------------------- #------------------------------------------------------------------------- #chp15.常用文字字串函數 #範例15-2:查詢文字內是否有某個字串 #https://www.w3schools.com/python/python_strings.asp #https://www.w3school.com.cn/python/python_strings.asp #https://www.runoob.com/python3/python3-string.html #1.----- 查詢某個字串是否在文字內?: if txt in a1 --------- a1 = "tom, john, mike, jolin" txt = "tom" if txt in a1: print(txt, "在文字內") else: print(txt, "不在文字內") #2.----- 查詢某個字串是否在文字內?: if txt in a1 --------- a1 = "tom, john, mike, jolin" txt = "tom" print(txt in a1) #3.----- 查詢某個字串是否不在文字內? if txt not in a1 --------- a1 = "tom, john, mike, jolin" txt = "peter" if not txt in a1: print(txt, "不在文字內") else: print(txt, "在文字內") #4.----- 文字的連接: + --------- a1 = "john" a2 = "0922111333" print(a1 + "的電話是" + a2) #-------------------------------------------------------------------------