strings and ints consistency - isinstance
Sayth Renshaw
flebber.crue at gmail.com
Wed Sep 21 10:26:33 EDT 2016
Hi
Trying to clarify why ints and strings arent treated the same.
You can get a valuerror from trying to cast a non-int to an int as in int(3.0) however you cannot do a non string with str(a).
Which means that you likely should use try and except to test if a user enters a non-int with valuerror.
However as you can't str () and get a valuerror you use conditional logic with strings.
Therefore to try and keep with pythons only one obvious way of doing things should i prefer conditional logic for all using isinstance?
That way regardless of input type my code flows the same and more explicitly states the intended type.
Sayth
More information about the Python-list
mailing list