I am working on a python program where I need to enter a hastag in the terminal in following manner:
[delta@localhost Desktop]$ python CheckHastag.py #football
after executing it throws out error as IndexError: list index out of range
It is because python is not accepting string starting with "#", however I tried without # i.e.
[delta@localhost Desktop]$ python CheckHastag.py football
it works.
So how do I make my program to accept the hashtag i.e string starting
with # ?
The shell treats # as the start of a comment, so the Python interpreter never gets to see what comes after the #.
This can be easily demonstrated using the echo command:
$ echo #football
$ echo football
football
You have several options for working around this:
$ python CheckHastag.py "#football"
$ python CheckHastag.py '#football'
$ python CheckHastag.py \#football
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With