Conversation
BethanyG
left a comment
There was a problem hiding this comment.
This largely looks good (nice work!). I might have more adjustments as we get the exercise going, but for now the changes are good and my suggestions are minimal.
Still noodling on if we want the related exercise to cover choosing between the methods, or if we only want to focus on f-strings. My first impulse is to do a mix of str.format() and f-strings, and leave the other stuff out. I worry that although template strings are important, they will confuse students, especially if/when we introduce Python 3.14s T-strings.
| `f-string` expressions cannot be empty, they cannot contain comments. | ||
| There are two main limitations to be aware of. | ||
| `f-string` expressions cannot be empty. | ||
| [Additionally, before Python 3.12, they cannot contain comments.][pep-0701] |
There was a problem hiding this comment.
| [Additionally, before Python 3.12, they cannot contain comments.][pep-0701] | |
| [Additionally, before Python 3.12, they could not contain comments.][pep-0701] |
| >>> verb = 'meet' | ||
|
|
||
| # This example includes a function, str, a nested f-string, an arithmetic expression, | ||
| # This example includes a function, an arithmetic expression, |
There was a problem hiding this comment.
Since the new specifications are explicit about both nesting and not needing to switch out the quotes, should we now include examples of nesting and switching quotes so that escapes don't get applied in results?
| - `!<conversion>` is optional and should be one of this three conversions: `!s` for [`str()`][str-conversion], `!r` for [`repr()`][repr-conversion] or `!a` for [`ascii()`][ascii-conversion]. | ||
| By default, `str()` is used. | ||
| - `:<format_specifier>` is optional and has a lot of options, which we are [listed here][format-specifiers]. | ||
| - `:<format_specifier>` is optional and has a lot of options, which are [listed here][format-specifiers]. |
There was a problem hiding this comment.
We might want to go into some detail here with different number formatting/alignment, since it's pretty common for formatting outputs in a table. Trey Hunner has some good examples.
| @@ -178,7 +179,9 @@ If you want to add multiple variables to a string, you need to supply a [tuple][ | |||
| ## Template Strings | |||
|
|
|||
| [`string.Template()`][string.Template()] is a class from the `string` module (_as opposed to the built-in `str` type_), which is part of the Python standard library, but has to be imported for use. | |||
There was a problem hiding this comment.
| [`string.Template()`][string.Template()] is a class from the `string` module (_as opposed to the built-in `str` type_), which is part of the Python standard library, but has to be imported for use. | |
| [`string.Template()`][string.Template()] (_not to be confused with Python 3.14 [t-strings](https://realpython.com/python-t-strings/)_) is a class from the `string` module (_as opposed to the built-in `str` type_), which is part of the Python standard library, but has to be imported for use. |
No description provided.