我在寫一個腳本時遇到問題。簡單地說,我的腳本執行以下操作:Python:搜索哈希標記符號
myvar = "#hashtag"
# I want an operation to return True IF the hash tag is the first character;
# however, the hash tag is used for commenting and will create an error in the
# program
# What I want to do
if myvar[0:1] == "#":
# Do something
如何完成此操作? 在此先感謝!
嘗試運行一些代碼。你會看到一個字符串文字中的磅符號*不被解釋爲註釋。 – chepner 2013-03-02 19:36:17