Francesco Maida wrote: > Esiste una funzione simile a String.isdigit(), che mi sappia dire se > una stringa contiene un numero ma che funzioni anche con i valori > decimali? > > Se ad esempio scrivo: > > >>> "3".isdigit() > True > >>> "3.14".isdigit() > False
Dalla doc: str.isdigit() Return true if all characters in the string are digits and there is at least one character, false otherwise. Non ti dice se una stringa contiene un numero, ma se tutti i caratteri nella stringa sono cifre (digit). > L'unica soluzione rapida che ho trovato è quella di mettere il tutto > in un blocco try..except, ma speravo che mi fosse sfuggito qualche > funzione built-in che facesse al caso mio. Non che io sappia. Un bel float('3.14') in un try...except è la cosa migliore. -- Nicola Larosa - http://www.tekNico.net/ The single most important kind of intelligence is the ability to see past your own strongly-held preconceptions and your tribe’s conventional wisdom and engage reality as it actually is and facts as they actually are. - Eric Raymond, April 2012 _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python