Come rilevare la hashtag nel testo in Python

June 30

Python è un open-source, linguaggio di programmazione interpretativo che contiene numerose funzioni e librerie utile per gli sviluppatori web. Durante la programmazione in Python, potrebbe essere necessario rilevare un tag hash in una stringa di testo. Ad esempio, si può decidere di cercare il testo immesso in un campo commento Web per vedere se un utente ha specificato un tag hash Twitter. In questo caso, è possibile utilizzare la funzione "stringa find" built-in.

istruzione

1 Apri il tuo editor di Python.

2 Digitare:

s = 'this_is_a_twitter

hashtag #';

s = s.find ( '#')

stampa s

3 Premere Invio."

ritorna Python "26."

In questo esempio, Python cerca la stringa di testo e trova il tag hash come il carattere 26 nella stringa.