Home > Mobile >  How to remove space between expression and period within a string? (Python 3)
How to remove space between expression and period within a string? (Python 3)

Time:05-15

Good Morning,

I've been trying to get rid of the space between the period and the number generated from sum(random_list) output [23739]. But can't seem to figure out how without turning the entire string to an f-string. I understand adding the comma will automatically insert a space, but can anyone let me know if there's an easier method? Thank you!

The picture below is my work;

Screen shot

CodePudding user response:

You can use format feature of string.

print("The sum of the elements in random list is {}.".format(sum(random_list)))

CodePudding user response:

I think this f-string should work

pritn(f"The sum of the elements in random list is {sum(random_list)}.")
  • Related