value1 = "10"
value2 = 10.2
print(int(value1))
print(int(value2))
balance_str = "1500.4"
balance_float = float(balance_str)
# print the type
print(type(balance_float))
# print the value
print(balance_float)
balance_str = "1500"
balance_int = int(balance_str)
# print the type
print(type(balance_int))
# print the value
print(balance_int)
def ignore_exception(IgnoreException=Exception,DefaultVal=None):
""" Decorator for ignoring exception from a function
e.g. @ignore_exception(DivideByZero)
e.g.2. ignore_exception(DivideByZero)(Divide)(2/0)
"""
def dec(function):
def _dec(*args, **kwargs):
try:
return function(*args, **kwargs)
except IgnoreException:
return DefaultVal
return _dec
return dec