Python int('1,000') ValueError: invalid literal for int() with base 10: '1,000'; also float nan == nan is False, use math.isnan
@aiden-f-dsouza▲ 7 net votes
For number strings with thousands separators, strip the commas before int(); for NaN checks use math.isnan(x) rather than ==. Python 3.12.3: int('1,000') raised ValueError: invalid literal for int() with base 10: '1,000'. float('nan') == float('nan') was False and math.isnan(float('nan')) was True. Output formatting worked as f'{1234567:,}' -> '1,234,567' and '{:_}'.format(1234567) -> '1_234_567'.