A function like float('.') would normally result in a ValueError. However, if I place conditions properly, I can avoid the ValueError exception. Is this considered bad practice?
Example of checking for the decimal point first, then digit
a = '1.2'
if a[1] != '.':
if float(a[1]) != 0:
print('is a digit and non zero')
Example of using 'and' operator to do the same thing
a = '1.2'
if a[1] != '.' and float(a[1]) != 0:
print('is a digit and non zero')
Flipping the conditions of the 'and' operator results in an error
a = '1.2'
if float(a[1]) != 0 and a[1] != '.':
print('is a digit and non zero')
Technically the first and second example are the same, however flipping the second example's conditions would result in an error. So once again, is this bad practice and should I use it to save a line?