python:f-strings

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン両方とも次のリビジョン
python:f-strings [2020/09/11 20:25] ともやんpython:f-strings [2023/05/08 08:33] – [書式編集のパフォーマンス比較] ともやん
行 38: 行 38:
 </WRAP> </WRAP>
 ===== 書式編集のパフォーマンス比較 ===== ===== 書式編集のパフォーマンス比較 =====
-<WRAP prewrap 100%>+<WRAP mincode_long> 
 +<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 "help", "copyright", "credits" or "license" for more information. 
 +>>> import timeit 
 +>>> timeit.timeit("""name = "TomoYan";age = 99; 
 +... f'{name} is {age}.'""", number = 1000000) 
 +0.23176945900195278 
 +>>> timeit.timeit("""name = "TomoYan";age = 99; 
 +... '%s is %s.' % (name, age)""", number = 1000000) 
 +0.22832379801548086 
 +>>> timeit.timeit("""name = "TomoYan";age = 99; 
 +... '{} is {}.'.format(name, age)""", number = 1000000) 
 +0.42849745802232064 
 +>>> timeit.timeit("""name = "TomoYan";age = 99; 
 +... '{0} is {1}.'.format(name, age)""", number = 1000000) 
 +0.5094511199858971 
 +>>>  
 +</code>
 <code python> <code python>
 $ python $ python
  • python/f-strings.txt
  • 最終更新: 2023/05/08 09:33
  • by ともやん