我在写一个脚本时遇到问题。简单地说,我的脚本执行以下操作: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