Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Ambdós costats versió prèvia Revisió prèvia Següent revisió | Revisió prèvia | ||
| development:python:strings [16/10/2023 02:13] – [string fill] mate | development:python:strings [10/10/2024 00:53] (actual) – [f-strings (Literal String Interpolation)] mate | ||
|---|---|---|---|
| Línia 1: | Línia 1: | ||
| = Python strings | = Python strings | ||
| + | {{tag> | ||
| == comp | == comp | ||
| * Exact match (equality comparison): | * Exact match (equality comparison): | ||
| Línia 13: | Línia 14: | ||
| * ''" | * ''" | ||
| * ''" | * ''" | ||
| - | * ''" | + | * ''" |
| - | * interpolación: | + | * interpolación |
| * Template strings | * Template strings | ||
| + | |||
| + | == f-strings (Literal String Interpolation) | ||
| + | * To create an f-string, prefix the string with the letter “ f ”. The string itself can be formatted in much the same way that you would with str.format(). F-strings provide a concise and convenient way to embed python expressions inside string literals for formatting. | ||
| + | * F-strings are faster than the two most commonly used string formatting mechanisms, which are % formatting and str.format(). | ||
| + | <code python> | ||
| + | val = ' | ||
| + | print(f" | ||
| + | </ | ||
| + | <code python> | ||
| + | import datetime | ||
| + | |||
| + | today = datetime.datetime.today() | ||
| + | print(f" | ||
| + | </ | ||
| + | Backslash Cannot be used in format string directly. | ||
| + | <code python error> | ||
| + | f" | ||
| + | </ | ||
| + | <code python correcto> | ||
| + | newline = ord(' | ||
| + | |||
| + | print(f" | ||
| + | </ | ||
| + | /+info: [[https:// | ||
| + | /via: [[https:// | ||
| == string fill | == string fill | ||