Maybe I was not clear, but my comments were that you don't need many of these (and certainly you don't need all from my first bullet), not that you should implement them differently (this does not apply to the inefficient ones).
Let's take for example add_commas. You would keep the number and use format where you want to print. In addition f-strings that are available in 3.6+ allow for calculations. Bottom line - generally you don't want to convert the number to string just for representation (i.e. with commas)
Let's take for example add_commas. You would keep the number and use format where you want to print. In addition f-strings that are available in 3.6+ allow for calculations. Bottom line - generally you don't want to convert the number to string just for representation (i.e. with commas)
num_items = 2500 price = 10 print('{:,d} items @ EUR {:.2f} per item --> Total EUR {:,.2F}'.format(num_items, price,num_items*price)) print(f'{num_items:,d} items @ EUR {price:.2f} per item --> Total EUR {num_items*price:,.2f}')
Output:2,500 items @ EUR 10.00 per item --> Total EUR 25,000.00
2,500 items @ EUR 10.00 per item --> Total EUR 25,000.00
or repeat - one would always use string multiplications (if not for something else, because it is shorter) than using repeat function.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs