[英]Why does this If Statement stop code execution?
我是Python的新手,我不明白為什么我的if
語句無法按預期工作。
我的for
循環使用一個函數列出文件名和內容類型
def listContentType(files):
contentType = "text/xml"
for filename in files:
if '.html' in filename :
contentType = 'text/html"
# do something
print(contentType)
但是, if
Statement返回true
,則print
不會打印'text / html'。
你知道為什么嗎?
您的代碼中有錯字。 您使用了兩種不同類型的引號來定義contentType
。
嘗試這個:
def listContentType(files):
for filename in files:
contentType = "text/xml"
if '.html' in filename :
contentType = 'text/html'
print(contentType)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.