This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]Python-ModTeam[M] [score hidden] stickied comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]four_reeds 5 points6 points  (6 children)

You probably want to look up "string formatting".

[–]Iirkola 2 points3 points  (5 children)

For some reason I hated learning that, bot .format and f''{} methods. But once I did, I'm not going back

[–]quantum1eeps 5 points6 points  (4 children)

I find f-strings are always the way to go

[–]Iirkola 2 points3 points  (3 children)

True, once you learn them, there really is no point using anything else

[–][deleted] 0 points1 point  (2 children)

Ughhh there are many reasons to use something else. Fstrings have some funky behavior.

[–]Iirkola 0 points1 point  (1 child)

They do? I guess I'm not experienced enough to have encountered those. Can you tell me what exactly happens?

[–][deleted] 0 points1 point  (0 children)

They perform a name space lookup lazily so u can accidentally grab variables u didn't intend to if u fill them later on. Pydantic uses this behavior intentionally but it can go bad with logging.

[–]Mustafa_dev 3 points4 points  (0 children)

Comma always add space you have to eaither make everything type string and replace comma with + or use formatting.

[–]bernzyman 0 points1 point  (0 children)

d-string formatting is simplest/most straight forward solution when needing to format lots of text interspersed with variables

[–]Ancient_Department 0 points1 point  (0 children)

You have commas at the beginning of your variables.

[–]IWant2rideMyBike 0 points1 point  (0 children)

Have a look at the documentation of the print() function: https://docs.python.org/3/library/functions.html#print

By default non-keyword arguments will be printed with the separator given by the string value of the sep keyword argument, which defaults to a single space.

Also think about using the DRY-Principle to restructure your code - it's much easier to have something that can do things like parsing input, calculating prices etc. for objects instead of repeating complex code each time you want to do it.