差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| python:f-strings [2020/05/31 07:58] – [書式編集のパフォーマンス比較] ともやん | python:f-strings [2023/05/08 09:33] (現在) – ともやん | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | < | + | ====== フォーマット済み文字列リテラル (f-strings) ====== |
| - | < | + | <WRAP mincode> |
| - | #mincode pre { | + | |
| - | /*height: 300px;*/ | + | |
| - | overflow: scroll; | + | |
| - | overflow-x: hidden; | + | |
| - | font-size: 10px; | + | |
| - | } | + | |
| - | # | + | |
| - | height: 400px; | + | |
| - | overflow: scroll; | + | |
| - | overflow-x: hidden; | + | |
| - | font-size: 10px; | + | |
| - | } | + | |
| - | #mintbl table { | + | |
| - | font-size: 12px; | + | |
| - | } | + | |
| - | .dokuwiki .plugin_wrap table { | + | |
| - | width: auto; | + | |
| - | } | + | |
| - | #result pre { | + | |
| - | /*height: 300px;*/ | + | |
| - | overflow: scroll; | + | |
| - | overflow-x: hidden; | + | |
| - | font-size: 10px; | + | |
| - | } | + | |
| - | </ | + | |
| - | </ | + | |
| - | ====== フォーマット済み文字列リテラル(f-strings) ====== | + | |
| - | < | + | |
| <code python> | <code python> | ||
| - | str_val = ' | + | >>> |
| - | f' | + | >>> |
| ' | ' | ||
| - | pi = 3.14159265358979 | + | >>> |
| - | f'pi: {pi: | + | >>> |
| 'pi: 3.14' | 'pi: 3.14' | ||
| - | f'pi: {pi: | + | >>> |
| ' | ' | ||
| - | flt_val = 123456789.0123456 | + | >>> |
| - | f' | + | >>> |
| 'float value: 123, | 'float value: 123, | ||
| - | flt_val = 1234.5678 | + | >>> |
| - | f' | + | >>> |
| 'float value: | 'float value: | ||
| - | f' | + | >>> |
| 'float value: | 'float value: | ||
| - | 'int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:# | + | >>> |
| 'int: 65536; hex: 0x10000; oct: 0o200000; bin: 0b10000000000000000' | 'int: 65536; hex: 0x10000; oct: 0o200000; bin: 0b10000000000000000' | ||
| + | |||
| + | >>> | ||
| + | >>> | ||
| + | ' | ||
| + | >>> | ||
| + | ' | ||
| + | >>> | ||
| + | ' title -------------' | ||
| + | >>> | ||
| </ | </ | ||
| </ | </ | ||
| ===== 書式編集のパフォーマンス比較 ===== | ===== 書式編集のパフォーマンス比較 ===== | ||
| - | < | + | < |
| <code python> | <code python> | ||
| + | $ python | ||
| + | Python 3.11.3 (main, Apr 5 2023, 00:00:00) [GCC 13.0.1 20230401 (Red Hat 13.0.1-0)] on linux | ||
| + | Type " | ||
| + | >>> | ||
| + | >>> | ||
| + | ... f' | ||
| + | 2.247387803014135 | ||
| + | >>> | ||
| + | ... '%s is %s.' % (name, age)""", | ||
| + | 2.269912829011446 | ||
| + | >>> | ||
| + | ... '{} is {}.' | ||
| + | 4.426570633018855 | ||
| + | >>> | ||
| + | ... '{0} is {1}.' | ||
| + | 5.005730772012612 | ||
| + | >>> | ||
| + | |||
| $ python | $ python | ||
| Python 3.8.3 (tags/ | Python 3.8.3 (tags/ | ||
| 行 85: | 行 84: | ||
| [[https:// | [[https:// | ||
| [[https:// | [[https:// | ||
| + | [[https:// | ||