Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中如何接受以#开头的字符串?_Python_Bash_Shell_Command Line_Command Line Arguments - Fatal编程技术网

在python中如何接受以#开头的字符串?

在python中如何接受以#开头的字符串?,python,bash,shell,command-line,command-line-arguments,Python,Bash,Shell,Command Line,Command Line Arguments,我正在开发一个python程序,需要以以下方式在终端中输入hastag: [delta@localhost Desktop]$ python CheckHastag.py #football 执行后,它抛出错误,如下所示 索引器:列表索引超出范围 这是因为python不接受以“#”开头的字符串,但是我尝试了不使用#,即 [delta@localhost Desktop]$ python CheckHastag.py football 它起作用了。 那么,如何使我的程序接受hashtag,即字

我正在开发一个python程序,需要以以下方式在终端中输入hastag:

[delta@localhost Desktop]$ python CheckHastag.py #football
执行后,它抛出错误,如下所示 索引器:列表索引超出范围

这是因为python不接受以“#”开头的字符串,但是我尝试了不使用
#
,即

[delta@localhost Desktop]$ python CheckHastag.py football
它起作用了。 那么,如何使我的程序接受hashtag,即字符串开始
使用#?

时,shell将
视为注释的开头,因此Python解释器永远无法看到
后面的内容

这可以使用
echo
命令轻松演示:

$ echo #football

$ echo football
football
您有几个解决此问题的选项:

$ python CheckHastag.py "#football"
$ python CheckHastag.py '#football'
$ python CheckHastag.py \#football

非常感谢你。