{"id":2577,"date":"2025-09-18T00:37:09","date_gmt":"2025-09-17T22:37:09","guid":{"rendered":"https:\/\/davidka.net\/en\/?p=2577"},"modified":"2025-11-02T22:12:17","modified_gmt":"2025-11-02T20:12:17","slug":"array-array-%d0%b2-python","status":"publish","type":"post","link":"https:\/\/ru.davidka.net\/ru\/arrayarray%D0%B2-python\/","title":{"rendered":"\ud83e\uddd1\u200d\ud83d\udcbb \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u00a0array.array\u00a0\u0432 Python: \u043a\u043e\u0433\u0434\u0430 \u0438 \u0437\u0430\u0447\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c"},"content":{"rendered":"\n<p class=\"has-neve-link-color-color has-text-color has-medium-font-size wp-block-paragraph\">\u041c\u043e\u0434\u0443\u043b\u044c&nbsp;<strong><code class=\"\" data-line=\"\">array<\/code><\/strong><code class=\"\" data-line=\"\">&nbsp;\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445&nbsp;array.array&nbsp;\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e&nbsp;list, \u043c\u0430\u0441\u0441\u0438\u0432\u044b&nbsp;array.array&nbsp;\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div id=\"rtoc-mokuji-wrapper\" class=\"rtoc-mokuji-content frame2 preset1 animation-fade rtoc_open default\" data-id=\"2577\" data-theme=\"Neve - Davidka\">\n\t\t\t<div id=\"rtoc-mokuji-title\" class=\"rtoc_btn_none rtoc_left\">\n\t\t\t\n\t\t\t<span>In Questo Articolo<\/span>\n\t\t\t<\/div><ol class=\"rtoc-mokuji decimal_ol level-1\"><li class=\"rtoc-item\"><a href=\"#rtoc-1\">\ud83d\udce6 \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430&nbsp;<code class=\"\" data-line=\"\">array.array<\/code><\/a><ul class=\"rtoc-mokuji mokuji_ul level-2\"><li class=\"rtoc-item\"><a href=\"#rtoc-2\">1. \u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043d\u0430\u0431\u043e\u0440\u0430\u043c\u0438 \u0447\u0438\u0441\u0435\u043b<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-3\">2. \u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-4\">3. \u041f\u0440\u044f\u043c\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 C-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 (<code class=\"\" data-line=\"\">ctypes<\/code>,&nbsp;<code class=\"\" data-line=\"\">struct<\/code>)<\/a><ul class=\"rtoc-mokuji mokuji_none level-3\"><li class=\"rtoc-item\"><a href=\"#rtoc-5\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441&nbsp;<code class=\"\" data-line=\"\">ctypes<\/code>:<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-6\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e&nbsp;<code class=\"\" data-line=\"\">struct<\/code>&nbsp;\u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-7\">4. \u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-8\">5. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u043e\u0441\u0442\u0438<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-9\">6. \u041f\u0440\u044f\u043c\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-10\">\ud83d\udd39 \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;vs&nbsp;<code class=\"\" data-line=\"\">list<\/code><\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-11\">\ud83e\uddd1\u200d\ud83d\udcbb \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0432 Python: \u043a\u043e\u0433\u0434\u0430 \u0438 \u0437\u0430\u0447\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-12\">\ud83d\udce6 \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430&nbsp;<code class=\"\" data-line=\"\">array.array<\/code><\/a><ul class=\"rtoc-mokuji mokuji_ul level-2\"><li class=\"rtoc-item\"><a href=\"#rtoc-13\">1. \u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043d\u0430\u0431\u043e\u0440\u0430\u043c\u0438 \u0447\u0438\u0441\u0435\u043b<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-14\">2. \u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-15\">3. \u041f\u0440\u044f\u043c\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 C-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 (<code class=\"\" data-line=\"\">ctypes<\/code>,&nbsp;<code class=\"\" data-line=\"\">struct<\/code>)<\/a><ul class=\"rtoc-mokuji mokuji_none level-3\"><li class=\"rtoc-item\"><a href=\"#rtoc-16\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441&nbsp;<code class=\"\" data-line=\"\">ctypes<\/code>:<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-17\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e&nbsp;<code class=\"\" data-line=\"\">struct<\/code>&nbsp;\u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-18\">4. \u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-19\">5. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u043e\u0441\u0442\u0438<\/a><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-20\">6. \u041f\u0440\u044f\u043c\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/a><\/li><\/ul><\/li><li class=\"rtoc-item\"><a href=\"#rtoc-21\">\ud83d\udd39 \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;vs&nbsp;<code class=\"\" data-line=\"\">list<\/code><\/a><\/li><\/ol><\/div><h2 id=\"rtoc-1\"  class=\"wp-block-heading\">\ud83d\udce6 \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430&nbsp;<code class=\"\" data-line=\"\">array.array<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u043e\u0442&nbsp;<code class=\"\" data-line=\"\">list<\/code>&nbsp;\u2014&nbsp;<strong>\u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>. \u0412\u043c\u0435\u0441\u0442\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Python,&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u0431\u043b\u043e\u043a \u0431\u0430\u0439\u0442\u043e\u0432, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-2\"  class=\"wp-block-heading\">1. \u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043d\u0430\u0431\u043e\u0440\u0430\u043c\u0438 \u0447\u0438\u0441\u0435\u043b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u043e\u0439.&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nimport sys\n\ndef compare_memory_usage(num_elements: int = 1_000_000) -&gt; None:\n    &quot;&quot;&quot;\n    \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 list \u0438 array.array.\n\n    Args:\n        num_elements (int, optional): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430. \n                                      \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1,000,000.\n    &quot;&quot;&quot;\n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 Python\n    list_numbers = list(range(num_elements))\n    \n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0433\u0434\u0435 \u0447\u0438\u0441\u043b\u0430 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u0430\u043a 4-\u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0435 C-\u0442\u0438\u043f\u044b int\n    array_numbers = array.array(&#039;i&#039;, range(num_elements))\n\n    list_size = sys.getsizeof(list_numbers)\n    array_size = sys.getsizeof(array_numbers)\n\n    print(f&quot;\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432: {num_elements}&quot;)\n    print(f&quot;\u0420\u0430\u0437\u043c\u0435\u0440 list:  {list_size \/ 1024 \/ 1024:.2f} MB&quot;)\n    print(f&quot;\u0420\u0430\u0437\u043c\u0435\u0440 array: {array_size \/ 1024 \/ 1024:.2f} MB&quot;)\n    if array_size &gt; 0:\n        print(f&quot;\u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438: {list_size \/ array_size:.2f}x&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    compare_memory_usage()\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0412\u044b\u0432\u043e\u0434:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432: 1000000\n\u0420\u0430\u0437\u043c\u0435\u0440 list:  7.63 MB\n\u0420\u0430\u0437\u043c\u0435\u0440 array: 3.82 MB\n\u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438: 2.00x\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-3\"  class=\"wp-block-heading\">2. \u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u044d\u0448.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nimport timeit\n\ndef compare_performance(num_elements: int = 10_000_000) -&gt; None:\n    &quot;&quot;&quot;\n    \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 list \u0438 array.array.\n\n    Args:\n        num_elements (int, optional): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430. \n                                      \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 10,000,000.\n    &quot;&quot;&quot;\n    setup_code = f&quot;&quot;&quot;\nimport array\ndata = range({num_elements})\nlist_data = list(data)\narray_data = array.array(&#039;i&#039;, data)\n&quot;&quot;&quot;\n    \n    # \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f list\n    list_time = timeit.timeit(&quot;sum(list_data)&quot;, setup=setup_code, number=10)\n    \n    # \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f array\n    array_time = timeit.timeit(&quot;sum(array_data)&quot;, setup=setup_code, number=10)\n    \n    print(f&quot;\u0412\u0440\u0435\u043c\u044f \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f {num_elements} \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (10 \u0440\u0430\u0437):&quot;)\n    print(f&quot;list:  {list_time:.4f} \u0441\u0435\u043a\u0443\u043d\u0434&quot;)\n    print(f&quot;array: {array_time:.4f} \u0441\u0435\u043a\u0443\u043d\u0434&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    compare_performance()\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0412\u044b\u0432\u043e\u0434:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432: 10000000\n\u0420\u0430\u0437\u043c\u0435\u0440 list:  2.1106 \u0441\u0435\u043a\u0443\u043d\u0434\n\u0420\u0430\u0437\u043c\u0435\u0440 array: 1.1549 \u0441\u0435\u043a\u0443\u043d\u0434\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-4\"  class=\"wp-block-heading\">3. \u041f\u0440\u044f\u043c\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 C-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 (<code class=\"\" data-line=\"\">ctypes<\/code>,&nbsp;<code class=\"\" data-line=\"\">struct<\/code>)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 C, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 C-\u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438.<\/p>\n\n\n\n<h4 id=\"rtoc-5\"  class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441&nbsp;<code class=\"\" data-line=\"\">ctypes<\/code>:<\/h4>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nfrom ctypes import c_double, CDLL\n\ndef demonstrate_ctypes_usage() -&gt; None:\n    &quot;&quot;&quot;\n    \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 array.array \u0432 C-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 ctypes.\n    &quot;&quot;&quot;\n    # \u041c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 (\u0442\u0438\u043f &#039;d&#039;)\n    py_array = array.array(&#039;d&#039;, &#091;1.1, 2.2, 3.3, 4.4])\n    \n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 C-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437 py_array\n    # \u0424\u0443\u043d\u043a\u0446\u0438\u044f (c_double * len(py_array)) \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u0438\u043f &quot;\u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 4-\u0445 c_double&quot;\n    # (*py_array) \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442 python-\u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\n    c_array = (c_double * len(py_array))(*py_array)\n\n    # \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0433 \u0431\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u043e\u0432 C-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:\n    # my_c_library = CDLL(&quot;.\/libmath.so&quot;)\n    # my_c_library.sum_doubles(c_array, len(c_array))\n    \n    print(f&quot;Python array: {py_array}&quot;)\n    print(f&quot;C-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 (ctypes): {&#091;val for val in c_array]}&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    demonstrate_ctypes_usage()\n<\/code><\/pre>\n\n\n\n<h4 id=\"rtoc-6\"  class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e&nbsp;<code class=\"\" data-line=\"\">struct<\/code>&nbsp;\u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/h4>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nimport struct\n\ndef demonstrate_struct_packing(data: list&#091;int]) -&gt; bytes:\n    &quot;&quot;&quot;\n    \u0423\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.\n\n    Args:\n        data (list&#091;int]): \u0421\u043f\u0438\u0441\u043e\u043a \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438.\n\n    Returns:\n        bytes: \u0411\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.\n    &quot;&quot;&quot;\n    arr = array.array(&#039;i&#039;, data)\n    \n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u0438\u0434\u0430 &#039;3i&#039; \u0434\u043b\u044f 3-\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b\n    format_string = f&#039;{len(arr)}i&#039;\n    \n    # \u0423\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442\n    binary_data = struct.pack(format_string, *arr)\n    \n    print(f&quot;\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: {arr}&quot;)\n    print(f&quot;\u0411\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: {binary_data}&quot;)\n    \n    # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430: \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\n    unpacked_data = struct.unpack(format_string, binary_data)\n    print(f&quot;\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: {unpacked_data}&quot;)\n    \n    return binary_data\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    demonstrate_struct_packing(&#091;10, 20, 30])\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-7\"  class=\"wp-block-heading\">4. \u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u0435\u0442\u043e\u0434\u044b&nbsp;<code class=\"\" data-line=\"\">.tobytes()<\/code>&nbsp;\u0438&nbsp;<code class=\"\" data-line=\"\">.frombytes()<\/code>&nbsp;\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0431\u0430\u0439\u0442\u044b \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0447\u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u044b \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u0435\u0442\u0438.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\n\ndef handle_binary_data() -&gt; None:\n    &quot;&quot;&quot;\n    \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e array.array \u0432 \u0431\u0430\u0439\u0442\u044b.\n    &quot;&quot;&quot;\n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430\n    source_array = array.array(&#039;i&#039;, &#091;1, 2, 3, 4, 5])\n    print(f&quot;\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: {source_array}&quot;)\n\n    # \u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0431\u0430\u0439\u0442\u044b\n    binary_data = source_array.tobytes()\n    print(f&quot;\u0414\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445: {binary_data}&quot;)\n\n    # \u0414\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0437 \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\n    new_array = array.array(&#039;i&#039;)\n    new_array.frombytes(binary_data)\n    print(f&quot;\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: {new_array}&quot;)\n\n    # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438\n    assert source_array == new_array, &quot;\u0414\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442!&quot;\n    print(&quot;\u0426\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0430.&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    handle_binary_data()\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-8\"  class=\"wp-block-heading\">5. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u043e\u0441\u0442\u0438<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. \u042d\u0442\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\n\ndef demonstrate_type_safety() -&gt; None:\n    &quot;&quot;&quot;\n    \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e array.array \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0438\u043f\u0430.\n    &quot;&quot;&quot;\n    arr = array.array(&#039;i&#039;, &#091;100, 200, 300])\n    print(f&quot;\u041c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b: {arr}&quot;)\n    \n    try:\n        # \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\n        arr.append(&#039;hello&#039;)\n    except TypeError as e:\n        # \u041e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\n        print(f&quot;\\n\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c &#039;hello&#039; \u0432\u044b\u0437\u0432\u0430\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0443: {e}&quot;)\n        print(&quot;\u042d\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u0443\u044e \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    demonstrate_type_safety()\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-9\"  class=\"wp-block-heading\">6. \u041f\u0440\u044f\u043c\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u0435\u0442\u043e\u0434\u044b&nbsp;<code class=\"\" data-line=\"\">.tofile()<\/code>&nbsp;\u0438&nbsp;<code class=\"\" data-line=\"\">.fromfile()<\/code>&nbsp;\u0443\u043f\u0440\u043e\u0449\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nfrom pathlib import Path\n\ndef work_with_binary_files(file_path_str: str = &quot;data.bin&quot;) -&gt; None:\n    &quot;&quot;&quot;\n    \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e.\n\n    Args:\n        file_path_str (str, optional): \u0418\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f.\n                                       \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e &quot;data.bin&quot;.\n    &quot;&quot;&quot;\n    file_path = Path(file_path_str)\n    source_array = array.array(&#039;f&#039;, &#091;1.5, 2.7, 3.14])\n\n    try:\n        # \u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\n        with file_path.open(&#039;wb&#039;) as f:\n            source_array.tofile(f)\n        print(f&quot;\u041c\u0430\u0441\u0441\u0438\u0432 {source_array} \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u0444\u0430\u0439\u043b &#039;{file_path}&#039;.&quot;)\n\n        # \u0427\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430\n        new_array = array.array(&#039;f&#039;)\n        with file_path.open(&#039;rb&#039;) as f:\n            # \u0427\u0442\u0435\u043d\u0438\u0435 3-\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 &#039;f&#039; (float)\n            new_array.fromfile(f, len(source_array))\n        print(f&quot;\u041c\u0430\u0441\u0441\u0438\u0432 {new_array} \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.&quot;)\n        \n        assert source_array == new_array\n        print(&quot;\u0426\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0430.&quot;)\n\n    finally:\n        # \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\n        if file_path.exists():\n            file_path.unlink()\n            print(f&quot;\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b &#039;{file_path}&#039; \u0443\u0434\u0430\u043b\u0435\u043d.&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    work_with_binary_files()\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"rtoc-10\"  class=\"wp-block-heading\">\ud83d\udd39 \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;vs&nbsp;<code class=\"\" data-line=\"\">list<\/code><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430<\/th><th><code class=\"\" data-line=\"\">array.array<\/code><\/th><th><code class=\"\" data-line=\"\">list<\/code><\/th><\/tr><\/thead><tbody><tr><td><strong>\u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/td><td>\u041e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b (\u0447\u0438\u0441\u043b\u0430, \u0441\u0438\u043c\u0432\u043e\u043b\u044b)<\/td><td>\u041b\u044e\u0431\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Python<\/td><\/tr><tr><td><strong>\u041f\u0430\u043c\u044f\u0442\u044c<\/strong><\/td><td>\u041d\u0438\u0437\u043a\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435<\/td><td>\u0412\u044b\u0441\u043e\u043a\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435<\/td><\/tr><tr><td><strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong><\/td><td>\u0412\u044b\u0441\u043e\u043a\u0430\u044f \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/td><td>\u041d\u0438\u0436\u0435 \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/td><\/tr><tr><td><strong>API<\/strong><\/td><td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/td><td>\u0411\u043e\u0433\u0430\u0442\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 API<\/td><\/tr><tr><td><strong>\u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 C<\/strong><\/td><td>\u0412\u044b\u0441\u043e\u043a\u0430\u044f, \u043f\u0440\u044f\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/td><td>\u0422\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/td><\/tr><tr><td><strong>\u0411\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/td><td>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (<code class=\"\" data-line=\"\">.tobytes<\/code>,&nbsp;<code class=\"\" data-line=\"\">.tofile<\/code>)<\/td><td>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f&nbsp;<code class=\"\" data-line=\"\">struct<\/code>,&nbsp;<code class=\"\" data-line=\"\">pickle<\/code>&nbsp;\u0438 \u0442.\u0434.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0412\u044b\u0432\u043e\u0434:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\ude80 \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043c\u0430\u043c\u0438&nbsp;<strong>\u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>, \u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b&nbsp;<strong>\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong>&nbsp;\u0438&nbsp;<strong>\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445,&nbsp;<code class=\"\" data-line=\"\">list<\/code>&nbsp;\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c.<\/p>\n\n\n\n<h2 id=\"rtoc-11\"  class=\"wp-block-heading\">\ud83e\uddd1\u200d\ud83d\udcbb \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0432 Python: \u043a\u043e\u0433\u0434\u0430 \u0438 \u0437\u0430\u0447\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u043e\u0434\u0443\u043b\u044c&nbsp;<strong><code class=\"\" data-line=\"\">array<\/code><\/strong><code class=\"\" data-line=\"\">&nbsp;\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445&nbsp;array.array&nbsp;\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e&nbsp;list, \u043c\u0430\u0441\u0441\u0438\u0432\u044b&nbsp;array.array&nbsp;\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"rtoc-12\"  class=\"wp-block-heading\">\ud83d\udce6 \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430&nbsp;<code class=\"\" data-line=\"\">array.array<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u043e\u0442&nbsp;<code class=\"\" data-line=\"\">list<\/code>&nbsp;\u2014&nbsp;<strong>\u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>. \u0412\u043c\u0435\u0441\u0442\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Python,&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u0431\u043b\u043e\u043a \u0431\u0430\u0439\u0442\u043e\u0432, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-13\"  class=\"wp-block-heading\">1. \u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043d\u0430\u0431\u043e\u0440\u0430\u043c\u0438 \u0447\u0438\u0441\u0435\u043b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0430\u0436\u043d\u043e\u0439.&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nimport sys\n\ndef compare_memory_usage(num_elements: int = 1_000_000) -&gt; None:\n    &quot;&quot;&quot;\n    \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 list \u0438 array.array.\n\n    Args:\n        num_elements (int, optional): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430. \n                                      \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1,000,000.\n    &quot;&quot;&quot;\n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 Python\n    list_numbers = list(range(num_elements))\n    \n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0433\u0434\u0435 \u0447\u0438\u0441\u043b\u0430 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u0430\u043a 4-\u0431\u0430\u0439\u0442\u043e\u0432\u044b\u0435 C-\u0442\u0438\u043f\u044b int\n    array_numbers = array.array(&#039;i&#039;, range(num_elements))\n\n    list_size = sys.getsizeof(list_numbers)\n    array_size = sys.getsizeof(array_numbers)\n\n    print(f&quot;\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432: {num_elements}&quot;)\n    print(f&quot;\u0420\u0430\u0437\u043c\u0435\u0440 list:  {list_size \/ 1024 \/ 1024:.2f} MB&quot;)\n    print(f&quot;\u0420\u0430\u0437\u043c\u0435\u0440 array: {array_size \/ 1024 \/ 1024:.2f} MB&quot;)\n    if array_size &gt; 0:\n        print(f&quot;\u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438: {list_size \/ array_size:.2f}x&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    compare_memory_usage()\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0412\u044b\u0432\u043e\u0434:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432: 1000000\n\u0420\u0430\u0437\u043c\u0435\u0440 list:  7.63 MB\n\u0420\u0430\u0437\u043c\u0435\u0440 array: 3.82 MB\n\u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438: 2.00x\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-14\"  class=\"wp-block-heading\">2. \u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u043c\u0443 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u044d\u0448.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nimport timeit\n\ndef compare_performance(num_elements: int = 10_000_000) -&gt; None:\n    &quot;&quot;&quot;\n    \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 list \u0438 array.array.\n\n    Args:\n        num_elements (int, optional): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430. \n                                      \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 10,000,000.\n    &quot;&quot;&quot;\n    setup_code = f&quot;&quot;&quot;\nimport array\ndata = range({num_elements})\nlist_data = list(data)\narray_data = array.array(&#039;i&#039;, data)\n&quot;&quot;&quot;\n    \n    # \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f list\n    list_time = timeit.timeit(&quot;sum(list_data)&quot;, setup=setup_code, number=10)\n    \n    # \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f array\n    array_time = timeit.timeit(&quot;sum(array_data)&quot;, setup=setup_code, number=10)\n    \n    print(f&quot;\u0412\u0440\u0435\u043c\u044f \u0441\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f {num_elements} \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (10 \u0440\u0430\u0437):&quot;)\n    print(f&quot;list:  {list_time:.4f} \u0441\u0435\u043a\u0443\u043d\u0434&quot;)\n    print(f&quot;array: {array_time:.4f} \u0441\u0435\u043a\u0443\u043d\u0434&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    compare_performance()\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0412\u044b\u0432\u043e\u0434:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432: 10000000\n\u0420\u0430\u0437\u043c\u0435\u0440 list:  2.1106 \u0441\u0435\u043a\u0443\u043d\u0434\n\u0420\u0430\u0437\u043c\u0435\u0440 array: 1.1549 \u0441\u0435\u043a\u0443\u043d\u0434\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-15\"  class=\"wp-block-heading\">3. \u041f\u0440\u044f\u043c\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 C-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 (<code class=\"\" data-line=\"\">ctypes<\/code>,&nbsp;<code class=\"\" data-line=\"\">struct<\/code>)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 C, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 C-\u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438.<\/p>\n\n\n\n<h4 id=\"rtoc-16\"  class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441&nbsp;<code class=\"\" data-line=\"\">ctypes<\/code>:<\/h4>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nfrom ctypes import c_double, CDLL\n\ndef demonstrate_ctypes_usage() -&gt; None:\n    &quot;&quot;&quot;\n    \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 array.array \u0432 C-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 ctypes.\n    &quot;&quot;&quot;\n    # \u041c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 (\u0442\u0438\u043f &#039;d&#039;)\n    py_array = array.array(&#039;d&#039;, &#091;1.1, 2.2, 3.3, 4.4])\n    \n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 C-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437 py_array\n    # \u0424\u0443\u043d\u043a\u0446\u0438\u044f (c_double * len(py_array)) \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u0438\u043f &quot;\u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 4-\u0445 c_double&quot;\n    # (*py_array) \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442 python-\u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\n    c_array = (c_double * len(py_array))(*py_array)\n\n    # \u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0433 \u0431\u044b \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u043e\u0432 C-\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:\n    # my_c_library = CDLL(&quot;.\/libmath.so&quot;)\n    # my_c_library.sum_doubles(c_array, len(c_array))\n    \n    print(f&quot;Python array: {py_array}&quot;)\n    print(f&quot;C-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 (ctypes): {&#091;val for val in c_array]}&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    demonstrate_ctypes_usage()\n<\/code><\/pre>\n\n\n\n<h4 id=\"rtoc-17\"  class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e&nbsp;<code class=\"\" data-line=\"\">struct<\/code>&nbsp;\u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/h4>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nimport struct\n\ndef demonstrate_struct_packing(data: list&#091;int]) -&gt; bytes:\n    &quot;&quot;&quot;\n    \u0423\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443.\n\n    Args:\n        data (list&#091;int]): \u0421\u043f\u0438\u0441\u043e\u043a \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0434\u043b\u044f \u0443\u043f\u0430\u043a\u043e\u0432\u043a\u0438.\n\n    Returns:\n        bytes: \u0411\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.\n    &quot;&quot;&quot;\n    arr = array.array(&#039;i&#039;, data)\n    \n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u0438\u0434\u0430 &#039;3i&#039; \u0434\u043b\u044f 3-\u0445 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b\n    format_string = f&#039;{len(arr)}i&#039;\n    \n    # \u0423\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442\n    binary_data = struct.pack(format_string, *arr)\n    \n    print(f&quot;\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: {arr}&quot;)\n    print(f&quot;\u0411\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: {binary_data}&quot;)\n    \n    # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430: \u0440\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u043a\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\n    unpacked_data = struct.unpack(format_string, binary_data)\n    print(f&quot;\u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435: {unpacked_data}&quot;)\n    \n    return binary_data\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    demonstrate_struct_packing(&#091;10, 20, 30])\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-18\"  class=\"wp-block-heading\">4. \u042d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u0435\u0442\u043e\u0434\u044b&nbsp;<code class=\"\" data-line=\"\">.tobytes()<\/code>&nbsp;\u0438&nbsp;<code class=\"\" data-line=\"\">.frombytes()<\/code>&nbsp;\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0431\u0430\u0439\u0442\u044b \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0447\u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u044b \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u043e \u0441\u0435\u0442\u0438.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\n\ndef handle_binary_data() -&gt; None:\n    &quot;&quot;&quot;\n    \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e array.array \u0432 \u0431\u0430\u0439\u0442\u044b.\n    &quot;&quot;&quot;\n    # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430\n    source_array = array.array(&#039;i&#039;, &#091;1, 2, 3, 4, 5])\n    print(f&quot;\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: {source_array}&quot;)\n\n    # \u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0431\u0430\u0439\u0442\u044b\n    binary_data = source_array.tobytes()\n    print(f&quot;\u0414\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445: {binary_data}&quot;)\n\n    # \u0414\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0437 \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\n    new_array = array.array(&#039;i&#039;)\n    new_array.frombytes(binary_data)\n    print(f&quot;\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432: {new_array}&quot;)\n\n    # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u0438\n    assert source_array == new_array, &quot;\u0414\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442!&quot;\n    print(&quot;\u0426\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0430.&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    handle_binary_data()\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-19\"  class=\"wp-block-heading\">5. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u044f \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u043e\u0441\u0442\u0438<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code class=\"\" data-line=\"\">array.array<\/code>&nbsp;\u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. \u042d\u0442\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\n\ndef demonstrate_type_safety() -&gt; None:\n    &quot;&quot;&quot;\n    \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e array.array \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0438\u043f\u0430.\n    &quot;&quot;&quot;\n    arr = array.array(&#039;i&#039;, &#091;100, 200, 300])\n    print(f&quot;\u041c\u0430\u0441\u0441\u0438\u0432 \u0446\u0435\u043b\u044b\u0445 \u0447\u0438\u0441\u0435\u043b: {arr}&quot;)\n    \n    try:\n        # \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\n        arr.append(&#039;hello&#039;)\n    except TypeError as e:\n        # \u041e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\n        print(f&quot;\\n\u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c &#039;hello&#039; \u0432\u044b\u0437\u0432\u0430\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0443: {e}&quot;)\n        print(&quot;\u042d\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u0443\u044e \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    demonstrate_type_safety()\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 id=\"rtoc-20\"  class=\"wp-block-heading\">6. \u041f\u0440\u044f\u043c\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u0435\u0442\u043e\u0434\u044b&nbsp;<code class=\"\" data-line=\"\">.tofile()<\/code>&nbsp;\u0438&nbsp;<code class=\"\" data-line=\"\">.fromfile()<\/code>&nbsp;\u0443\u043f\u0440\u043e\u0449\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u043c\u0438 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n\n\n\n<pre class=\"wp-block-code line-numbers\"><code class=\" language-python\" data-line=\"\">import array\nfrom pathlib import Path\n\ndef work_with_binary_files(file_path_str: str = &quot;data.bin&quot;) -&gt; None:\n    &quot;&quot;&quot;\n    \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e.\n\n    Args:\n        file_path_str (str, optional): \u0418\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f.\n                                       \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e &quot;data.bin&quot;.\n    &quot;&quot;&quot;\n    file_path = Path(file_path_str)\n    source_array = array.array(&#039;f&#039;, &#091;1.5, 2.7, 3.14])\n\n    try:\n        # \u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\n        with file_path.open(&#039;wb&#039;) as f:\n            source_array.tofile(f)\n        print(f&quot;\u041c\u0430\u0441\u0441\u0438\u0432 {source_array} \u0437\u0430\u043f\u0438\u0441\u0430\u043d \u0432 \u0444\u0430\u0439\u043b &#039;{file_path}&#039;.&quot;)\n\n        # \u0427\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430\n        new_array = array.array(&#039;f&#039;)\n        with file_path.open(&#039;rb&#039;) as f:\n            # \u0427\u0442\u0435\u043d\u0438\u0435 3-\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 &#039;f&#039; (float)\n            new_array.fromfile(f, len(source_array))\n        print(f&quot;\u041c\u0430\u0441\u0441\u0438\u0432 {new_array} \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.&quot;)\n        \n        assert source_array == new_array\n        print(&quot;\u0426\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0430.&quot;)\n\n    finally:\n        # \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\n        if file_path.exists():\n            file_path.unlink()\n            print(f&quot;\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b &#039;{file_path}&#039; \u0443\u0434\u0430\u043b\u0435\u043d.&quot;)\n\n# \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\nif __name__ == &quot;__main__&quot;:\n    work_with_binary_files()\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 id=\"rtoc-21\"  class=\"wp-block-heading\">\ud83d\udd39 \u0421\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430:&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>&nbsp;vs&nbsp;<code class=\"\" data-line=\"\">list<\/code><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u0425\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430<\/th><th><code class=\"\" data-line=\"\">array.array<\/code><\/th><th><code class=\"\" data-line=\"\">list<\/code><\/th><\/tr><\/thead><tbody><tr><td><strong>\u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445<\/strong><\/td><td>\u041e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b (\u0447\u0438\u0441\u043b\u0430, \u0441\u0438\u043c\u0432\u043e\u043b\u044b)<\/td><td>\u041b\u044e\u0431\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Python<\/td><\/tr><tr><td><strong>\u041f\u0430\u043c\u044f\u0442\u044c<\/strong><\/td><td>\u041d\u0438\u0437\u043a\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435<\/td><td>\u0412\u044b\u0441\u043e\u043a\u043e\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435<\/td><\/tr><tr><td><strong>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong><\/td><td>\u0412\u044b\u0441\u043e\u043a\u0430\u044f \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/td><td>\u041d\u0438\u0436\u0435 \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/td><\/tr><tr><td><strong>API<\/strong><\/td><td>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/td><td>\u0411\u043e\u0433\u0430\u0442\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 API<\/td><\/tr><tr><td><strong>\u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 C<\/strong><\/td><td>\u0412\u044b\u0441\u043e\u043a\u0430\u044f, \u043f\u0440\u044f\u043c\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/td><td>\u0422\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/td><\/tr><tr><td><strong>\u0411\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong><\/td><td>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (<code class=\"\" data-line=\"\">.tobytes<\/code>,&nbsp;<code class=\"\" data-line=\"\">.tofile<\/code>)<\/td><td>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f&nbsp;<code class=\"\" data-line=\"\">struct<\/code>,&nbsp;<code class=\"\" data-line=\"\">pickle<\/code>&nbsp;\u0438 \u0442.\u0434.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0412\u044b\u0432\u043e\u0434:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\ude80 \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435&nbsp;<code class=\"\" data-line=\"\">array.array<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043c\u0430\u043c\u0438&nbsp;<strong>\u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong>, \u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b&nbsp;<strong>\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/strong>&nbsp;\u0438&nbsp;<strong>\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445,&nbsp;<code class=\"\" data-line=\"\">list<\/code>&nbsp;\u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041c\u043e\u0434\u0443\u043b\u044c\u00a0array\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445\u00a0array.array\u00a0\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e\u00a0list, \u043c\u0430\u0441\u0441\u0438\u0432\u044b\u00a0array.array\u00a0\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n","protected":false},"author":1,"featured_media":3771,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"left","neve_meta_author_avatar":"on","neve_post_elements_order":"[\"content\",\"tags\",\"comments\"]","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[610],"tags":[852,984,985,853],"class_list":["post-2577","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-basics","tag-tag-python-2","tag-array-array","tag-dict","tag-tag-data-structures"],"acf":[],"_links":{"self":[{"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/posts\/2577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/comments?post=2577"}],"version-history":[{"count":0,"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/posts\/2577\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/media\/3771"}],"wp:attachment":[{"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/media?parent=2577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/categories?post=2577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ru.davidka.net\/ru\/wp-json\/wp\/v2\/tags?post=2577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}