#Python TQC考題806 字元次數計算
def compute(s,c):return
#只因題目指定需def compute()
#實際不需要此行
s=input()
c=input()
cnt=s.count(c)
#計算c在s中出現了幾次
print(“%s occurs %d time(s)” %(c,cnt))

#題目希望的寫法:
def compute(s,c):return s.count(c)
s=input()
c=input()
print(“%s occurs %d time(s)” %(c,compute(s,c)))


def compute(sent,word):
return sent.count(word)
sent=input()
word=input()
print(word,”occurs”,str(compute(sent,word)),”times(s)”)
#字串間用逗點分隔,自動生出空白
#用+連接,沒有空白


#string就可以.count()了
#不用轉成list,多此一舉了!






![Python如何串接OpenAI /Claude /Gemini API自動將大量維修紀錄JSON轉自然語言描述(並避免中斷資料遺失)response = client.chat.completions.create() ; reply = response.choices[0].message.content Python如何串接OpenAI /Claude /Gemini API自動將大量維修紀錄JSON轉自然語言描述(並避免中斷資料遺失)response = client.chat.completions.create() ; reply = response.choices[0].message.content](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/07/20250716084059_0_c5b368.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python `typing.NamedTuple` (`collections.namedtuple`) 與 `typing.Literal` 教學 — 用型別「防止錯配」; StripRule = NamedTuple(“StripRule”, [(“regex”, re.Pattern), (“flag”, str)]) vs StripRule = namedtuple(“StripRule”, [“regex”, “flag”]) Python `typing.NamedTuple` (`collections.namedtuple`) 與 `typing.Literal` 教學 — 用型別「防止錯配」; StripRule = NamedTuple(“StripRule”, [(“regex”, re.Pattern), (“flag”, str)]) vs StripRule = namedtuple(“StripRule”, [“regex”, “flag”])](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2026/07/20260702150603_0_86abc2.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言