Skip to content

Comments

Tweaks to string-formatting concept#4099

Open
BNAndras wants to merge 1 commit intoexercism:mainfrom
BNAndras:update-string-formatting
Open

Tweaks to string-formatting concept#4099
BNAndras wants to merge 1 commit intoexercism:mainfrom
BNAndras:update-string-formatting

Conversation

@BNAndras
Copy link
Member

No description provided.

@BethanyG
Copy link
Member

You should add yourself to the contributors list here and the links doc might need an update or once-over. 🙂 More comments as I finish up my coffee.

Copy link
Member

@BethanyG BethanyG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[`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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants