number = input("Enter the number:")
''' Let's suppose the entered number is 0145. Question is below.'''
I want to add a comma after 0. How can i do this?
number = input("Enter the number:")
''' Let's suppose the entered number is 0145. Question is below.'''
I want to add a comma after 0. How can i do this?
Use {:,}
to format a number with commas in Python.
Example:
number = 1000
print(f"{number:,}")
Output: 1,000
If want a general purpose number formatter for numbers as strings that may include leading 0's then there is a solution using regular expressions here. If user enters "0145" and want to format that as "0,145" then you'd need to use the string input rather than converting to an integer which would drop any leading 0's.