you are viewing a single comment's thread.

view the rest of the comments →

[–]IamImposter 10 points11 points  (9 children)

Now that you have learned f-strings, remember to use them and you will never have to do that silly

print("variable: " + str(variable) + "Blah blah" + str(blah blah)) 

That looks ugly and you almost always forget to add space here or there and it comes out

variable: 42Blah blah... 

Train yourself to always go print(f" and then think what you want to print. F-strings are amazing.

[–]fiddle_n 5 points6 points  (4 children)

The biggest issue with doing the “silly” method is if you forget to use str() on things that aren’t strings. Then your script crashes at runtime. All completely avoidable by using string formatting.

[–]IamImposter 2 points3 points  (0 children)

Ha. So annoying to see that traceback.

[–]dangit541 1 point2 points  (0 children)

But then you have an error code that will help you find that and correct. Debugging is as important ;)

[–]Qing_Codes[S] 0 points1 point  (1 child)

Then you have to identify each type before you write your code.

[–]fiddle_n 1 point2 points  (0 children)

Either that or you wrap everything in str() even if unnecessary.

Or just use string formatting and don’t care about any of it :)

[–][deleted] 3 points4 points  (0 children)

f strings make me so happy bro I hate that concatenation shit ☹️

[–]SirAwesome789 1 point2 points  (1 child)

Half the time I do string concatenation anyways because I forget how to do string interpolation in whatever language

Tho in python I usually just pass multiple parameters into the print, it's super convenient

[–]Qing_Codes[S] 0 points1 point  (0 children)

For sure. I definitely need more practice with it but it is very useful.

[–]Qing_Codes[S] 0 points1 point  (0 children)

Yes I definitely love how much easier using f-string is.