Python for .NET Developers Transcripts
Chapter: Web frameworks
Lecture: Improved price display

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well, this is nice, I really love how it came out. Except, if you look carefully wouldn't it be nice if there was a comma right there?
0:08 1,299. If we have more than, you know, three digits? So, it's really easy to do that in Python and we just use string.format.
0:17 I don't think in the course yet we've used string.format, we've only used f-strings Python's equivalent of C#'s string interpolation
0:25 but we're going to do that here to get a better representation. There's probably a ton of ways to do this but we can just put two quotes here
0:32 and we can say, we want something formatted in here zero, quoting point, and it has commas for digit grouping and we say .format, this.
0:44 Let's see if I got that right, whoops, no, I did not. There we go, let's see if I got that right. Try again, ta-da, there it is.
0:52 So, you know, nothing major or groundbreaking but if you want to control the two string bit here you just write a little Python expression
0:58 with a string.format, and you can go crazy.

Talk Python's Mastodon Michael Kennedy's Mastodon