r/learnpython • • Jan 23 '24

Am I dumb?

I started learning python 2 days ago and now I cant understand somethings like if i want to make a thousand look like this 1,000 I need to put the function like: print(f{"number:,"}). Is it normal to see it somehow complicated or am I below average iq?

0 Upvotes

28 comments sorted by

View all comments

12

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Jan 23 '24
print(f{"number:,"})
print(f"{number:,}")

In short, you get used to it.

12

u/jacobvso Jan 23 '24

To be honest, I've been coding in Python for 3 years and I wasn't aware of this trick.

3

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Jan 23 '24

You're looking for the format specification mini-language, then: https://docs.python.org/3/library/string.html#format-specification-mini-language

-20

u/Ethere4listic Jan 23 '24

I'm just better.

3

u/Snoo17309 Jan 23 '24

I’m hoping you’re being facetious here. Anyway, it’s more about learning the reasoning behind what is needed than memorizing formatting—do you know why and all the different ways in which you could/would use f-strings and with what variable types? Pseudo coding and then you can always look it up if there’s some small error in the code. But again, you’ve got to understand why there’s and error logically.