On 12/05/2019 12:31, Matthew Polack wrote: > result = str(' Cost: ' + '${:.2f}'.format(cost)) > > But I don't understamd what the curly brace part is actually doing:
> ..curly braces apparenly are for dictionaries...but I don't get how this is > a dictionary..or what this {:} command is actually doing? Curly braces inside a string are nothing to do with dictionaries or sets(which also use them). They are placeholders for inserted data using the format() string method. Search the docs for string formatting, you will find a page on the subject with many examples. (or you could read the "Simple Sequences" topic in my tutorial - about half way down - see below) There is another, older style of formatting that uses % characters instead of {}. You will see both styles used regularly in Python code. Some folks prefer one, some the other. They are both very powerful ways of constructing output strings with data inserted. {} and format() has a few extra tricks once you get into advanced uses, but % style does most of the same things (and has the advantage of being used in other languages too so you only need to remember one style!). -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor