python:f-strings

差分

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

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
最新のリビジョン両方とも次のリビジョン
python:f-strings [2020/05/31 16:55] ともやんpython:f-strings [2023/05/08 09:08] – [書式編集のパフォーマンス比較] ともやん
行 1: 行 1:
-<html> 
-  <style> 
-    #result pre, #mincode pre { 
-      overflow: hidden; 
-      font-size: 10px; 
-    } 
-    #result_long pre { 
-      height: 250px; 
-      overflow: scroll; 
-      overflow-x: hidden; 
-      font-size: 10px; 
-    } 
-    #mintbl table { 
-      font-size: 12px; 
-    } 
-    #mintbl td pre { 
-      margin: 0; 
-    } 
-    #img_long { 
-      height: 400px; 
-      overflow: scroll; 
-      overflow-x: hidden; 
-    } 
-    .dokuwiki .plugin_wrap table { 
-      width: auto; 
-    } 
-    #logo { 
-      background-color: white; 
-      padding: 10px; 
-      width: fit-content; 
-    } 
-    #logo p { 
-      margin: 0; 
-    } 
-  </style> 
-</html> 
 ====== フォーマット済み文字列リテラル (f-strings) ====== ====== フォーマット済み文字列リテラル (f-strings) ======
 <WRAP prewrap 100%> <WRAP prewrap 100%>
行 74: 行 38:
 </WRAP> </WRAP>
 ===== 書式編集のパフォーマンス比較 ===== ===== 書式編集のパフォーマンス比較 =====
-<WRAP prewrap 100%>+<WRAP mincode_long>
 <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 "help", "copyright", "credits" or "license" for more information.
 +>>> import timeit
 +>>> timeit.timeit("""name = "TomoYan";age = 99;
 +... f'{name} is {age}.'""", number = 10000000)
 +2.247387803014135
 +>>> timeit.timeit("""name = "TomoYan";age = 99;
 +... '%s is %s.' % (name, age)""", number = 10000000)
 +2.269912829011446
 +>>> timeit.timeit("""name = "TomoYan";age = 99;
 +... '{} is {}.'.format(name, age)""", number = 10000000)
 +4.426570633018855
 +>>> timeit.timeit("""name = "TomoYan";age = 99;
 +... '{0} is {1}.'.format(name, age)""", number = 10000000)
 +5.005730772012612
 +>>> ^D
 +
 $ python $ python
 Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32 Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
  • python/f-strings.txt
  • 最終更新: 2023/05/08 09:33
  • by ともやん