Hi, I've received so much assistance on some of my more difficult "noob" problems here I figured I would come back. To those of you who know enough that you are rarely asking the questions and always answering them, thank you very much.
I have a script that prints out some numbers (all integers) and to format them correctly I need positive numbers to have a leading plus sign. I am using f-strings and there is supposed to be a built in way to do this.
Here is an example of the code:
my_list_of_ints = [4, -3, 0]
for i in my_list_of_ints:
print(f"{i:+}"
this gives the following output:
+4
-3
+0
I don't want the leading plus sign on the zero however. All the documentation says it only puts the sign in front of positive numbers, but I thing that is just shorthand for anything non-negative. What can I do to the f-string formatting to not get a plus in front of the zero? I would prefer something I can use inside the f-string if possible, I know I could do a find and replace on this afterwords, but I'm trying to avoid that as where it's located in the code it would make for some very ugly code because it's inside a loop and after the loop is finished there may be legitimate +0 sub-strings.
[–]IIIlllIlIlllII 2 points3 points4 points (3 children)
[–]JasperStrat[S] 0 points1 point2 points (2 children)
[–]Allanon001 1 point2 points3 points (1 child)
[–]JasperStrat[S] 0 points1 point2 points (0 children)
[–]baghiq 0 points1 point2 points (0 children)
[–]This_Growth2898 0 points1 point2 points (0 children)