Il 11 maggio 2016 16:31, Pietro Battiston <m...@pietrobattiston.it> ha scritto: > ... condensare ... > > if not civico.isdigit(): > raise ValueError("Il numero civico deve essere numerico") > > in > > assert(civico.isdigit()) "Il numero civico deve essere numerico" > Uso assert se il controllo:
- non deve influire sul flusso del programma; - rappresenta condizioni inaspettate e quindi un bug del programma; - come placeholder nelle fasi preliminari - chiarito meglio il flusso li sostituisco con eccezioni; eg. ``` ret = factorial(n) assert ret, "Factorial can't be negative. BUG in the program!" print(ret) ``` _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python