diff --git a/tutorial/classes.po b/tutorial/classes.po index 86181bce3..d05610989 100644 --- a/tutorial/classes.po +++ b/tutorial/classes.po @@ -15,15 +15,15 @@ msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-07-25 12:59+0330\n" -"PO-Revision-Date: 2021-06-28 01:49+0000\n" +"PO-Revision-Date: 2026-08-13 09:09+0330\n" "Last-Translator: khosro azimi, 2025\n" -"Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/" -"fa/)\n" +"Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/fa/)\n" "Language: fa\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Generator: Poedit 3.6\n" #: ../../tutorial/classes.rst:5 msgid "Classes" @@ -31,78 +31,49 @@ msgstr "کلاسها" #: ../../tutorial/classes.rst:7 msgid "" -"Classes provide a means of bundling data and functionality together. " -"Creating a new class creates a new *type* of object, allowing new " -"*instances* of that type to be made. Each class instance can have " -"attributes attached to it for maintaining its state. Class instances can " -"also have methods (defined by its class) for modifying its state." +"Classes provide a means of bundling data and functionality together. Creating a new class creates a new *type* of object, allowing new *instances* of that type to " +"be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for " +"modifying its state." msgstr "" -"کلاسها وسیله‌ای را برای بسته‌بندی کردن داده و عملکرد با هم فراهم می‌کنند. " -"ایجاد یک کلاس جدید، نوع جدیدی ایجاد می‌کند که اجازه می‌دهد موارد جدیدی از آن " -"نوع ساخته شود. هر نمونه از کلاس می‌تواند صفاتی داشته باشد که به آن متصل شده‌اند " -"تا وضعیت آن را حفظ کنند. نمونه‌های کلاس می‌توانند همچنین متد‌هایی (که " -"توسط کلاس تعریف شده‌اند) داشته باشند تا وضعیت آن را تغییر دهند." +"کلاسها وسیله‌ای را برای بسته‌بندی کردن داده و عملکرد با هم فراهم می‌کنند. ایجاد یک کلاس جدید، نوع جدیدی ایجاد می‌کند که اجازه می‌دهد موارد جدیدی از آن نوع ساخته شود. هر " +"نمونه از کلاس می‌تواند صفاتی داشته باشد که به آن متصل شده‌اند تا وضعیت آن را حفظ کنند. نمونه‌های کلاس می‌توانند همچنین متد‌هایی (که توسط کلاس تعریف شده‌اند) داشته باشند " +"تا وضعیت آن را تغییر دهند." #: ../../tutorial/classes.rst:13 msgid "" -"Compared with other programming languages, Python's class mechanism adds " -"classes with a minimum of new syntax and semantics. It is a mixture of the " -"class mechanisms found in C++ and Modula-3. Python classes provide all the " -"standard features of Object Oriented Programming: the class inheritance " -"mechanism allows multiple base classes, a derived class can override any " -"methods of its base class or classes, and a method can call the method of a " -"base class with the same name. Objects can contain arbitrary amounts and " -"kinds of data. As is true for modules, classes partake of the dynamic " -"nature of Python: they are created at runtime, and can be modified further " -"after creation." -msgstr "" -"در مقایسه با دیگر زبانهای برنامه‌نویسی، مکانیزم کلاس در پایتون کلاسها را " -"با حداقل قواعد و معناشناسی جدید اضافه می‌کند. این مکانیزم ترکیبی از مکانیزم‌های " -"کلاسی است که در C++ و Modula-3 یافت می‌شود. کلاسهای پایتون تمام ویژگیهای " -"استاندارد برنامه‌نویسی شیءگرا را فراهم می‌کنند: مکانیزم ارث بری کلاسها " -"اجازه می‌دهد کلاسهای پایه‌ی متعددی داشته باشید، یک کلاس مشتق می‌تواند هر یک " -"از متد‌های کلاسهای پایه‌ی خود را بازنویسی کند و یک متد می‌تواند متدی از کلاس " -"پایه با همان نام را فراخوانی کند. اشیاء می‌توانند حاوی مقادیر و انواع داده‌ای " -"دلخواه باشند. همان‌طور که برای ماژول‌ها صادق است، کلاسها نیز از طبیعت " -"پویا در پایتون برخوردارند: آن‌ها در زمان اجرا ایجاد می‌شوند و می‌توانند پس " -"از ایجاد بیشتر تغییر داده شوند." +"Compared with other programming languages, Python's class mechanism adds classes with a minimum of new syntax and semantics. It is a mixture of the class " +"mechanisms found in C++ and Modula-3. Python classes provide all the standard features of Object Oriented Programming: the class inheritance mechanism allows " +"multiple base classes, a derived class can override any methods of its base class or classes, and a method can call the method of a base class with the same name. " +"Objects can contain arbitrary amounts and kinds of data. As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and " +"can be modified further after creation." +msgstr "" +"در مقایسه با دیگر زبانهای برنامه‌نویسی، مکانیزم کلاس در پایتون کلاسها را با حداقل قواعد و معناشناسی جدید اضافه می‌کند. این مکانیزم ترکیبی از مکانیزم‌های کلاسی است که " +"در C++ و Modula-3 یافت می‌شود. کلاسهای پایتون تمام ویژگیهای استاندارد برنامه‌نویسی شیءگرا را فراهم می‌کنند: مکانیزم ارث بری کلاسها اجازه می‌دهد کلاسهای پایه‌ی متعددی " +"داشته باشید، یک کلاس مشتق می‌تواند هر یک از متد‌های کلاسهای پایه‌ی خود را بازنویسی کند و یک متد می‌تواند متدی از کلاس پایه با همان نام را فراخوانی کند. اشیاء می‌توانند " +"حاوی مقادیر و انواع داده‌ای دلخواه باشند. همان‌طور که برای ماژول‌ها صادق است، کلاسها نیز از طبیعت پویا در پایتون برخوردارند: آن‌ها در زمان اجرا ایجاد می‌شوند و می‌توانند " +"پس از ایجاد بیشتر تغییر داده شوند." #: ../../tutorial/classes.rst:23 msgid "" -"In C++ terminology, normally class members (including the data members) are " -"*public* (except see below :ref:`tut-private`), and all member functions are " -"*virtual*. As in Modula-3, there are no shorthands for referencing the " -"object's members from its methods: the method function is declared with an " -"explicit first argument representing the object, which is provided " -"implicitly by the call. As in Smalltalk, classes themselves are objects. " -"This provides semantics for importing and renaming. Unlike C++ and " -"Modula-3, built-in types can be used as base classes for extension by the " -"user. Also, like in C++, most built-in operators with special syntax " -"(arithmetic operators, subscripting etc.) can be redefined for class " -"instances." -msgstr "" -"در اصطلاحات C++، معمولاً اعضای کلاس (از جمله اعضای داده) *public* هستند (به " -"جز موردی که در پایین :ref:`tut-private` ذکر شده است)، و تمامی توابع عضو " -"مجازی هستند. همان‌طور که در Modula-3، هیچ میانبر‌هایی برای ارجاع به اعضای " -"شیء از متد‌های آن وجود ندارد: تابع متد با یک آرگومان اول صریح که نمایانگر شیء " -"است، اعلام می‌شود که این آرگومان به صورت ضمنی توسط فراخوانی فراهم می‌شود. " -"همان‌طور که در Smalltalk، خود کلاسها اشیاء هستند. این ویژگی معناشناسی برای " -"وارد کردن و تغییر نام را فراهم می‌آورد. برخلاف C++ و Modula-3، نوع‌های داخلی " -"می‌توانند به‌عنوان کلاسهای پایه برای توسعه توسط کاربر استفاده شوند. همچنین، " -"مانند C++، بیشتر عملگر‌های داخلی با نحوی خاص (عملگر‌های ریاضی، زیرنویسی و " -"غیره) می‌توانند برای نمونه‌های کلاس بازتعریف شوند." +"In C++ terminology, normally class members (including the data members) are *public* (except see below :ref:`tut-private`), and all member functions are *virtual*. " +"As in Modula-3, there are no shorthands for referencing the object's members from its methods: the method function is declared with an explicit first argument " +"representing the object, which is provided implicitly by the call. As in Smalltalk, classes themselves are objects. This provides semantics for importing and " +"renaming. Unlike C++ and Modula-3, built-in types can be used as base classes for extension by the user. Also, like in C++, most built-in operators with special " +"syntax (arithmetic operators, subscripting etc.) can be redefined for class instances." +msgstr "" +"در اصطلاحات C++، معمولاً اعضای کلاس (از جمله اعضای داده) *public* هستند (به جز موردی که در پایین :ref:`tut-private` ذکر شده است)، و تمامی توابع عضو مجازی هستند. " +"همان‌طور که در Modula-3، هیچ میانبر‌هایی برای ارجاع به اعضای شیء از متد‌های آن وجود ندارد: تابع متد با یک آرگومان اول صریح که نمایانگر شیء است، اعلام می‌شود که این " +"آرگومان به صورت ضمنی توسط فراخوانی فراهم می‌شود. همان‌طور که در Smalltalk، خود کلاسها اشیاء هستند. این ویژگی معناشناسی برای وارد کردن و تغییر نام را فراهم می‌آورد. " +"برخلاف C++ و Modula-3، نوع‌های داخلی می‌توانند به‌عنوان کلاسهای پایه برای توسعه توسط کاربر استفاده شوند. همچنین، مانند C++، بیشتر عملگر‌های داخلی با نحوی خاص (عملگر‌های " +"ریاضی، زیرنویسی و غیره) می‌توانند برای نمونه‌های کلاس بازتعریف شوند." #: ../../tutorial/classes.rst:34 msgid "" -"(Lacking universally accepted terminology to talk about classes, I will make " -"occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, " -"since its object-oriented semantics are closer to those of Python than C++, " -"but I expect that few readers have heard of it.)" +"(Lacking universally accepted terminology to talk about classes, I will make occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, since its " +"object-oriented semantics are closer to those of Python than C++, but I expect that few readers have heard of it.)" msgstr "" -"(با نبود اصطلاحات پذیرفته شده جهانی برای صحبت درباره‌ی کلاسها، گاهی از " -"اصطلاحات Smalltalk و C++ استفاده خواهم کرد. من از اصطلاحات Modula-3 استفاده " -"می‌کردم، چون معنای شیء‌گرای آن به پایتون نزدیک‌تر از C++ است، اما انتظار دارم " -"که تعداد کمی از خوانندگان با آن آشنا باشند.)" +"(با نبود اصطلاحات پذیرفته شده جهانی برای صحبت درباره‌ی کلاسها، گاهی از اصطلاحات Smalltalk و C++ استفاده خواهم کرد. من از اصطلاحات Modula-3 استفاده می‌کردم، چون معنای " +"شیء‌گرای آن به پایتون نزدیک‌تر از C++ است، اما انتظار دارم که تعداد کمی از خوانندگان با آن آشنا باشند.)" #: ../../tutorial/classes.rst:43 msgid "A Word About Names and Objects" @@ -110,30 +81,18 @@ msgstr "سخنی درباره‌ی نام‌ها و اشیاء" #: ../../tutorial/classes.rst:45 msgid "" -"Objects have individuality, and multiple names (in multiple scopes) can be " -"bound to the same object. This is known as aliasing in other languages. " -"This is usually not appreciated on a first glance at Python, and can be " -"safely ignored when dealing with immutable basic types (numbers, strings, " -"tuples). However, aliasing has a possibly surprising effect on the " -"semantics of Python code involving mutable objects such as lists, " -"dictionaries, and most other types. This is usually used to the benefit of " -"the program, since aliases behave like pointers in some respects. For " -"example, passing an object is cheap since only a pointer is passed by the " -"implementation; and if a function modifies an object passed as an argument, " -"the caller will see the change --- this eliminates the need for two " -"different argument passing mechanisms as in Pascal." -msgstr "" -"اشیاء هویت فردی دارند و چندین نام (در چندین محدوده) می‌توانند به یک شیء " -"مشخص متصل شوند. این در زبانهای دیگر با نام «اسم‌های مستعار» شناخته می‌شود. " -"این ویژگی معمولاً در نگاه اول به پایتون چندان جلب توجه نمی‌کند و هنگام کار با " -"انواع پایه‌ی تغییرناپذیر (اعداد، رشته‌ها، تاپل‌ها) می‌توان آن را نادیده گرفت. " -"با این حال، نام‌های مستعار می‌توانند تأثیری شگفت‌آور بر معناشناسی کد پایتونی " -"داشته باشند، به‌ویژه هنگامی که با اشیاء تغییرپذیر مانند لیستها، دیکشنری‌ها و " -"بیشتر انواع دیگر سروکار داریم. این ویژگی معمولاً به سود برنامه تمام می‌شود، " -"چون نام‌های مستعار از برخی جهات مانند اشاره‌گرها (pointer) رفتار می‌کنند. " -"برای مثال، ارسال یک شیء به‌عنوان آرگومان ارزان است، چون پیاده‌سازی فقط یک اشاره‌گر را " -"ارسال می‌کند؛ و اگر تابعی شیء‌ای را که به‌عنوان آرگومان دریافت کرده تغییر دهد، " -"فراخوان‌نده تغییر را مشاهده خواهد کرد --- این کار نیاز به دو مکانیزم متفاوت " +"Objects have individuality, and multiple names (in multiple scopes) can be bound to the same object. This is known as aliasing in other languages. This is usually " +"not appreciated on a first glance at Python, and can be safely ignored when dealing with immutable basic types (numbers, strings, tuples). However, aliasing has a " +"possibly surprising effect on the semantics of Python code involving mutable objects such as lists, dictionaries, and most other types. This is usually used to the " +"benefit of the program, since aliases behave like pointers in some respects. For example, passing an object is cheap since only a pointer is passed by the " +"implementation; and if a function modifies an object passed as an argument, the caller will see the change --- this eliminates the need for two different argument " +"passing mechanisms as in Pascal." +msgstr "" +"اشیاء هویت فردی دارند و چندین نام (در چندین محدوده) می‌توانند به یک شیء مشخص متصل شوند. این در زبانهای دیگر با نام «اسم‌های مستعار» شناخته می‌شود. این ویژگی معمولاً در " +"نگاه اول به پایتون چندان جلب توجه نمی‌کند و هنگام کار با انواع پایه‌ی تغییرناپذیر (اعداد، رشته‌ها، تاپل‌ها) می‌توان آن را نادیده گرفت. با این حال، نام‌های مستعار می‌توانند " +"تأثیری شگفت‌آور بر معناشناسی کد پایتونی داشته باشند، به‌ویژه هنگامی که با اشیاء تغییرپذیر مانند لیستها، دیکشنری‌ها و بیشتر انواع دیگر سروکار داریم. این ویژگی معمولاً به " +"سود برنامه تمام می‌شود، چون نام‌های مستعار از برخی جهات مانند اشاره‌گرها (pointer) رفتار می‌کنند. برای مثال، ارسال یک شیء به‌عنوان آرگومان ارزان است، چون پیاده‌سازی فقط " +"یک اشاره‌گر را ارسال می‌کند؛ و اگر تابعی شیء‌ای را که به‌عنوان آرگومان دریافت کرده تغییر دهد، فراخوان‌نده تغییر را مشاهده خواهد کرد --- این کار نیاز به دو مکانیزم متفاوت " "برای ارسال آرگومان (مانند آنچه در پاسکال وجود دارد) را از بین می‌برد." #: ../../tutorial/classes.rst:61 @@ -142,17 +101,11 @@ msgstr "محدوده‌ها و فضای نام‌ها در پایتون" #: ../../tutorial/classes.rst:63 msgid "" -"Before introducing classes, I first have to tell you something about " -"Python's scope rules. Class definitions play some neat tricks with " -"namespaces, and you need to know how scopes and namespaces work to fully " -"understand what's going on. Incidentally, knowledge about this subject is " -"useful for any advanced Python programmer." +"Before introducing classes, I first have to tell you something about Python's scope rules. Class definitions play some neat tricks with namespaces, and you need to " +"know how scopes and namespaces work to fully understand what's going on. Incidentally, knowledge about this subject is useful for any advanced Python programmer." msgstr "" -"قبل از معرفی کلاسها، ابتدا باید چیزی درباره‌ی قوانین حوزه در پایتون به شما " -"بگویم. تعریف کلاسها چند ترفند جالب با فضا‌های نام انجام می‌دهد و برای اینکه " -"به‌طور کامل متوجه شوید چه می‌گذرد، باید بدانید که حوزه‌ها و فضا‌های نام چگونه " -"کار می‌کنند. ضمناً، آگاهی از این موضوع برای هر برنامه‌نویس پیشرفته‌ی پایتون " -"مفید است." +"قبل از معرفی کلاسها، ابتدا باید چیزی درباره‌ی قوانین حوزه در پایتون به شما بگویم. تعریف کلاسها چند ترفند جالب با فضا‌های نام انجام می‌دهد و برای اینکه به‌طور کامل " +"متوجه شوید چه می‌گذرد، باید بدانید که حوزه‌ها و فضا‌های نام چگونه کار می‌کنند. ضمناً، آگاهی از این موضوع برای هر برنامه‌نویس پیشرفته‌ی پایتون مفید است." #: ../../tutorial/classes.rst:69 msgid "Let's begin with some definitions." @@ -160,117 +113,74 @@ msgstr "بیایید با چند تعریف شروع کنیم." #: ../../tutorial/classes.rst:71 msgid "" -"A *namespace* is a mapping from names to objects. Most namespaces are " -"currently implemented as Python dictionaries, but that's normally not " -"noticeable in any way (except for performance), and it may change in the " -"future. Examples of namespaces are: the set of built-in names (containing " -"functions such as :func:`abs`, and built-in exception names); the global " -"names in a module; and the local names in a function invocation. In a sense " -"the set of attributes of an object also form a namespace. The important " -"thing to know about namespaces is that there is absolutely no relation " -"between names in different namespaces; for instance, two different modules " -"may both define a function ``maximize`` without confusion --- users of the " -"modules must prefix it with the module name." -msgstr "" -"«فضای نام» *namespace* نگاشتی است از نام‌ها به اشیا. بیشتر فضای نام‌ها در حال " -"حاضر به‌صورت دیکشنری‌های پایتون پیاده‌سازی شده‌اند، اما معمولاً این موضوع (به جز " -"در بازدهی قابل مشاهده نیست و ممکن است در آینده تغییر کند. " -"مثالهایی از فضای نام عبارت‌اند از: مجموعه نام‌های داخلی (که شامل توابعی " -"مثل :func:`abs` و نام‌های استثنائات داخلی است)؛ نام‌های سراسری در یک ماژول؛ و " -"نام‌های محلی در یک فراخوانی تابع. به نوعی، مجموعه صفات «attributes» یک شیء نیز " -"یک فضای نام را تشکیل می‌دهد. نکته‌ی مهم درباره‌ی فضای نام‌ها این است که هیچ " -"ارتباطی بین نام‌ها در فضای نام‌های مختلف وجود ندارد؛ برای مثال، دو ماژول مختلف " -"می‌توانند هر دو تابعی با نام ``maximize`` تعریف کنند بدون اینکه ابهامی پیش " -"بیاید — استفاده‌کنندگان از ماژول‌ها باید نام ماژول را به عنوان پیشوند بیاورند." +"A *namespace* is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that's normally not noticeable in any way " +"(except for performance), and it may change in the future. Examples of namespaces are: the set of built-in names (containing functions such as :func:`abs`, and " +"built-in exception names); the global names in a module; and the local names in a function invocation. In a sense the set of attributes of an object also form a " +"namespace. The important thing to know about namespaces is that there is absolutely no relation between names in different namespaces; for instance, two different " +"modules may both define a function ``maximize`` without confusion --- users of the modules must prefix it with the module name." +msgstr "" +"«فضای نام» *namespace* نگاشتی است از نام‌ها به اشیا. بیشتر فضای نام‌ها در حال حاضر به‌صورت دیکشنری‌های پایتون پیاده‌سازی شده‌اند، اما معمولاً این موضوع (به جز در بازدهی " +"قابل مشاهده نیست و ممکن است در آینده تغییر کند. مثالهایی از فضای نام عبارت‌اند از: مجموعه نام‌های داخلی (که شامل توابعی مثل :func:`abs` و نام‌های استثنائات داخلی است)؛ " +"نام‌های سراسری در یک ماژول؛ و نام‌های محلی در یک فراخوانی تابع. به نوعی، مجموعه صفات «attributes» یک شیء نیز یک فضای نام را تشکیل می‌دهد. نکته‌ی مهم درباره‌ی فضای نام‌ها " +"این است که هیچ ارتباطی بین نام‌ها در فضای نام‌های مختلف وجود ندارد؛ برای مثال، دو ماژول مختلف می‌توانند هر دو تابعی با نام ``maximize`` تعریف کنند بدون اینکه ابهامی " +"پیش بیاید — استفاده‌کنندگان از ماژول‌ها باید نام ماژول را به عنوان پیشوند بیاورند." #: ../../tutorial/classes.rst:82 msgid "" -"By the way, I use the word *attribute* for any name following a dot --- for " -"example, in the expression ``z.real``, ``real`` is an attribute of the " -"object ``z``. Strictly speaking, references to names in modules are " -"attribute references: in the expression ``modname.funcname``, ``modname`` is " -"a module object and ``funcname`` is an attribute of it. In this case there " -"happens to be a straightforward mapping between the module's attributes and " -"the global names defined in the module: they share the same namespace! [#]_" -msgstr "" -"به‌هرحال، من واژه‌ی *ویژگی* «*attribute*» را برای هر نامی که بعد از یک نقطه " -"بیاید به کار می‌برم — برای مثال، در عبارت ``z.real``, ``real`` یک ویژگی شیء " -"``z`` است. از نظر دقیق‌تر، ارجاع به نام‌ها در ماژول‌ها نیز نوعی ارجاع به ویژگی " -"محسوب می‌شود: در عبارت ``modname.funcname``, ``modname`` یک شیء ماژول است و " -"``funcname`` یکی از ویژگیهای آن است. در این حالت، نگاشتی ساده و مستقیم بین " -"ویژگیهای ماژول و نام‌های سراسری تعریف‌شده در آن وجود دارد: هر دو یک فضای نام " -"(namespace) را به اشتراک می‌گذارند! [#]_" +"By the way, I use the word *attribute* for any name following a dot --- for example, in the expression ``z.real``, ``real`` is an attribute of the object ``z``. " +"Strictly speaking, references to names in modules are attribute references: in the expression ``modname.funcname``, ``modname`` is a module object and ``funcname`` " +"is an attribute of it. In this case there happens to be a straightforward mapping between the module's attributes and the global names defined in the module: they " +"share the same namespace! [#]_" +msgstr "" +"به‌هرحال، من واژه‌ی *ویژگی* «*attribute*» را برای هر نامی که بعد از یک نقطه بیاید به کار می‌برم — برای مثال، در عبارت ``z.real``, ``real`` یک ویژگی شیء ``z`` است. از " +"نظر دقیق‌تر، ارجاع به نام‌ها در ماژول‌ها نیز نوعی ارجاع به ویژگی محسوب می‌شود: در عبارت ``modname.funcname``, ``modname`` یک شیء ماژول است و ``funcname`` یکی از " +"ویژگیهای آن است. در این حالت، نگاشتی ساده و مستقیم بین ویژگیهای ماژول و نام‌های سراسری تعریف‌شده در آن وجود دارد: هر دو یک فضای نام (namespace) را به اشتراک می‌گذارند! " +"[#]_" #: ../../tutorial/classes.rst:90 msgid "" -"Attributes may be read-only or writable. In the latter case, assignment to " -"attributes is possible. Module attributes are writable: you can write " -"``modname.the_answer = 42``. Writable attributes may also be deleted with " -"the :keyword:`del` statement. For example, ``del modname.the_answer`` will " -"remove the attribute :attr:`!the_answer` from the object named by " -"``modname``." +"Attributes may be read-only or writable. In the latter case, assignment to attributes is possible. Module attributes are writable: you can write " +"``modname.the_answer = 42``. Writable attributes may also be deleted with the :keyword:`del` statement. For example, ``del modname.the_answer`` will remove the " +"attribute :attr:`!the_answer` from the object named by ``modname``." msgstr "" -"ویژگیها ممکن است فقط خواندنی یا قابل نوشتن باشند. در حالت دوم، اختصاص دادن " -"به ویژگیها ممکن است. ویژگیهای ماژول قابل نوشتن هستند: می‌توانید " -"``modname.the_answer = 42`` را بنویسید. ویژگیهای قابل نوشتن را می‌توان با " -"دستور :keyword:`del` نیز حذف کرد. به عنوان مثال، ``del modname.the_answer`` " -"ویژگی :attr:`!the_answer` را از شیئی که توسط ``modname`` نامگذاری شده است " -"حذف خواهد کرد." +"ویژگیها ممکن است فقط خواندنی یا قابل نوشتن باشند. در حالت دوم، اختصاص دادن به ویژگیها ممکن است. ویژگیهای ماژول قابل نوشتن هستند: می‌توانید ``modname.the_answer = " +"42`` را بنویسید. ویژگیهای قابل نوشتن را می‌توان با دستور :keyword:`del` نیز حذف کرد. به عنوان مثال، ``del modname.the_answer`` ویژگی :attr:`!the_answer` را از شیئی " +"که توسط ``modname`` نامگذاری شده است حذف خواهد کرد." #: ../../tutorial/classes.rst:96 msgid "" -"Namespaces are created at different moments and have different lifetimes. " -"The namespace containing the built-in names is created when the Python " -"interpreter starts up, and is never deleted. The global namespace for a " -"module is created when the module definition is read in; normally, module " -"namespaces also last until the interpreter quits. The statements executed " -"by the top-level invocation of the interpreter, either read from a script " -"file or interactively, are considered part of a module " -"called :mod:`__main__`, so they have their own global namespace. (The built-" -"in names actually also live in a module; this is called :mod:`builtins`.)" -msgstr "" -"فضا‌های نام در لحظات مختلف ایجاد می‌شوند و دارای طول عمر‌های متفاوتی هستند. " -"فضای نام که شامل نام‌های داخلی است، زمانی که مفسر پایتون شروع به کار می‌کند " -"ایجاد می‌شود و هرگز حذف نمی‌شود. فضای نام عمومی برای یک ماژول زمانی که تعریف " -"ماژول خوانده می‌شود ایجاد می‌گردد؛ به‌طور معمول، فضا‌های نام ماژول نیز تا " -"زمانی که مفسر پایان یابد باقی می‌مانند. دستوراتی که توسط اجرای سطح بالای " -"مفسر، یا از فایل اسکریپت خوانده شده یا به‌طور تعاملی اجرا می‌شوند، به عنوان " -"بخشی از ماژولی به نام :mod:`__main__` در نظر گرفته می‌شوند، بنابراین آن‌ها " -"فضای نام عمومی خود را دارند. (نام‌های درون‌ساخت نیز در واقع در یک ماژول قرار " -"دارند؛ این ماژول :mod:`builtins` نامیده می‌شود.)" +"Namespaces are created at different moments and have different lifetimes. The namespace containing the built-in names is created when the Python interpreter starts " +"up, and is never deleted. The global namespace for a module is created when the module definition is read in; normally, module namespaces also last until the " +"interpreter quits. The statements executed by the top-level invocation of the interpreter, either read from a script file or interactively, are considered part of " +"a module called :mod:`__main__`, so they have their own global namespace. (The built-in names actually also live in a module; this is called :mod:`builtins`.)" +msgstr "" +"فضا‌های نام در لحظات مختلف ایجاد می‌شوند و دارای طول عمر‌های متفاوتی هستند. فضای نام که شامل نام‌های داخلی است، زمانی که مفسر پایتون شروع به کار می‌کند ایجاد می‌شود و " +"هرگز حذف نمی‌شود. فضای نام عمومی برای یک ماژول زمانی که تعریف ماژول خوانده می‌شود ایجاد می‌گردد؛ به‌طور معمول، فضا‌های نام ماژول نیز تا زمانی که مفسر پایان یابد باقی " +"می‌مانند. دستوراتی که توسط اجرای سطح بالای مفسر، یا از فایل اسکریپت خوانده شده یا به‌طور تعاملی اجرا می‌شوند، به عنوان بخشی از ماژولی به نام :mod:`__main__` در نظر " +"گرفته می‌شوند، بنابراین آن‌ها فضای نام عمومی خود را دارند. (نام‌های درون‌ساخت نیز در واقع در یک ماژول قرار دارند؛ این ماژول :mod:`builtins` نامیده می‌شود.)" #: ../../tutorial/classes.rst:106 msgid "" -"The local namespace for a function is created when the function is called, " -"and deleted when the function returns or raises an exception that is not " -"handled within the function. (Actually, forgetting would be a better way to " -"describe what actually happens.) Of course, recursive invocations each have " -"their own local namespace." +"The local namespace for a function is created when the function is called, and deleted when the function returns or raises an exception that is not handled within " +"the function. (Actually, forgetting would be a better way to describe what actually happens.) Of course, recursive invocations each have their own local namespace." msgstr "" -"فضای نام محلی برای یک تابع زمانی ایجاد می‌شود که تابع فراخوانی شود و زمانی که " -"تابع بازمی‌گردد یا استثنایی پرتاب می‌کند که در درون تابع مدیریت نمی‌شود، حذف " -"می‌گردد. (در واقع، «فراموش شدن» توصیف بهتری برای چیزی است که واقعاً اتفاق " -"می‌افتد.) البته، هر فراخوانی بازگشتی، فضای نام محلی خودش را دارد." +"فضای نام محلی برای یک تابع زمانی ایجاد می‌شود که تابع فراخوانی شود و زمانی که تابع بازمی‌گردد یا استثنایی پرتاب می‌کند که در درون تابع مدیریت نمی‌شود، حذف می‌گردد. (در " +"واقع، «فراموش شدن» توصیف بهتری برای چیزی است که واقعاً اتفاق می‌افتد.) البته، هر فراخوانی بازگشتی، فضای نام محلی خودش را دارد." #: ../../tutorial/classes.rst:112 msgid "" -"A *scope* is a textual region of a Python program where a namespace is " -"directly accessible. \"Directly accessible\" here means that an unqualified " -"reference to a name attempts to find the name in the namespace." +"A *scope* is a textual region of a Python program where a namespace is directly accessible. \"Directly accessible\" here means that an unqualified reference to a " +"name attempts to find the name in the namespace." msgstr "" -"یک *دامنه* «*scope*» یک ناحیه‌ی متنی از یک برنامه‌ی پایتون است که در آن یک فضای " -"نام «namespace» به‌طور مستقیم قابل دستیابی است. \"به‌طور مستقیم قابل " -"دستیابی\" در اینجا به این معنی است که یک ارجاع بدون صلاحیت به یک نام تلاش می‌کند " -"تا نام «name» را در فضای نام «namespace» پیدا کند." +"یک *دامنه* «*scope*» یک ناحیه‌ی متنی از یک برنامه‌ی پایتون است که در آن یک فضای نام «namespace» به‌طور مستقیم قابل دستیابی است. \"به‌طور مستقیم قابل دستیابی\" در اینجا " +"به این معنی است که یک ارجاع بدون صلاحیت به یک نام تلاش می‌کند تا نام «name» را در فضای نام «namespace» پیدا کند." #: ../../tutorial/classes.rst:116 msgid "" -"Although scopes are determined statically, they are used dynamically. At any " -"time during execution, there are 3 or 4 nested scopes whose namespaces are " -"directly accessible:" +"Although scopes are determined statically, they are used dynamically. At any time during execution, there are 3 or 4 nested scopes whose namespaces are directly " +"accessible:" msgstr "" -"اگرچه محدوده‌ها به‌صورت ایستا تعیین می‌شوند، اما به‌صورت پویا مورد استفاده قرار می‌گیرند. در هر " -"زمان حین اجرا، ۳ یا ۴ محدوده‌ی تو در تو وجود دارند که فضاهای نام آن‌ها " +"اگرچه محدوده‌ها به‌صورت ایستا تعیین می‌شوند، اما به‌صورت پویا مورد استفاده قرار می‌گیرند. در هر زمان حین اجرا، ۳ یا ۴ محدوده‌ی تو در تو وجود دارند که فضاهای نام آن‌ها " "مستقیماً قابل دسترسی هستند:" #: ../../tutorial/classes.rst:120 @@ -278,100 +188,66 @@ msgid "the innermost scope, which is searched first, contains the local names" msgstr "درونی‌ترین حوزه، که ابتدا جستجو می‌شود، شامل نام‌های محلی است" #: ../../tutorial/classes.rst:121 -msgid "" -"the scopes of any enclosing functions, which are searched starting with the " -"nearest enclosing scope, contain non-local, but also non-global names" -msgstr "" -"محدوده‌های هر تابع محاط‌شونده، که جستجو از نزدیک‌ترین " -"محدوده‌ی محاط‌شونده آغاز می‌شود، شامل نام‌های غیرمحلی و همچنین غیرسراسری هستند." +msgid "the scopes of any enclosing functions, which are searched starting with the nearest enclosing scope, contain non-local, but also non-global names" +msgstr "محدوده‌های هر تابع محاط‌شونده، که جستجو از نزدیک‌ترین محدوده‌ی محاط‌شونده آغاز می‌شود، شامل نام‌های غیرمحلی و همچنین غیرسراسری هستند" #: ../../tutorial/classes.rst:123 msgid "the next-to-last scope contains the current module's global names" -msgstr "حوزه‌ی قبل از آخر شامل نام‌های عمومی ماژول جاری است." +msgstr "حوزه‌ی قبل از آخر شامل نام‌های عمومی ماژول جاری است" #: ../../tutorial/classes.rst:124 -msgid "" -"the outermost scope (searched last) is the namespace containing built-in " -"names" -msgstr "" -"بیرونی‌ترین محدوده (که آخر از همه جستجو می‌شود) فضای نامی است که شامل " -"نام‌های توکار است." +msgid "the outermost scope (searched last) is the namespace containing built-in names" +msgstr "بیرونی‌ترین محدوده (که آخر از همه جستجو می‌شود) فضای نامی است که شامل نام‌های توکار است" #: ../../tutorial/classes.rst:126 msgid "" -"If a name is declared global, then all references and assignments go " -"directly to the next-to-last scope containing the module's global names. To " -"rebind variables found outside of the innermost scope, " -"the :keyword:`nonlocal` statement can be used; if not declared nonlocal, " -"those variables are read-only (an attempt to write to such a variable will " -"simply create a *new* local variable in the innermost scope, leaving the " -"identically named outer variable unchanged)." -msgstr "" -"اگر یک نام به‌عنوان سراسری اعلام شود، تمام ارجاعها و تخصیص‌ها مستقیماً به " -"محدوده‌ی یکی‌مانده‌به‌آخر که شامل نام‌های سراسری ماژول است، می‌روند. برای " -"اتصال مجدد متغیرهایی که در خارج از درونی‌ترین محدوده یافت می‌شوند، " -"می‌توان از دستور :keyword:`nonlocal` استفاده کرد؛ اگر به‌عنوان nonlocal اعلام نشوند، " -"آن متغیرها فقط‌خواندنی هستند (تلاش برای نوشتن در چنین متغیری، صرفاً یک متغیر محلی *جدید* در " -"درونی‌ترین محدوده ایجاد می‌کند و متغیر بیرونی با همان نام را بدون تغییر باقی می‌گذارد)." +"If a name is declared global, then all references and assignments go directly to the next-to-last scope containing the module's global names. To rebind variables " +"found outside of the innermost scope, the :keyword:`nonlocal` statement can be used; if not declared nonlocal, those variables are read-only (an attempt to write to " +"such a variable will simply create a *new* local variable in the innermost scope, leaving the identically named outer variable unchanged)." +msgstr "" +"اگر یک نام به‌عنوان سراسری اعلام شود، تمام ارجاعها و تخصیص‌ها مستقیماً به محدوده‌ی یکی‌مانده‌به‌آخر که شامل نام‌های سراسری ماژول است، می‌روند. برای اتصال مجدد متغیرهایی که " +"در خارج از درونی‌ترین محدوده یافت می‌شوند، می‌توان از دستور :keyword:`nonlocal` استفاده کرد؛ اگر به‌عنوان nonlocal اعلام نشوند، آن متغیرها فقط‌خواندنی هستند (تلاش برای " +"نوشتن در چنین متغیری، صرفاً یک متغیر محلی *جدید* در درونی‌ترین محدوده ایجاد می‌کند و متغیر بیرونی با همان نام را بدون تغییر باقی می‌گذارد)." #: ../../tutorial/classes.rst:133 msgid "" -"Usually, the local scope references the local names of the (textually) " -"current function. Outside functions, the local scope references the same " -"namespace as the global scope: the module's namespace. Class definitions " -"place yet another namespace in the local scope." +"Usually, the local scope references the local names of the (textually) current function. Outside functions, the local scope references the same namespace as the " +"global scope: the module's namespace. Class definitions place yet another namespace in the local scope." msgstr "" -"معمولاً، محدوده‌ی محلی به نام‌های محلی تابع جاری (از نظر متنی) ارجاع می‌دهد. " -"در خارج از توابع، محدوده‌ی محلی به همان فضای نامی ارجاع می‌دهد که محدوده‌ی سراسری " -"به آن ارجاع می‌دهد: فضای نام ماژول. تعاریف کلاسها، فضای نام دیگری را در محدوده‌ی محلی قرار می‌دهند." +"معمولاً، محدوده‌ی محلی به نام‌های محلی تابع جاری (از نظر متنی) ارجاع می‌دهد. در خارج از توابع، محدوده‌ی محلی به همان فضای نامی ارجاع می‌دهد که محدوده‌ی سراسری به آن ارجاع " +"می‌دهد: فضای نام ماژول. تعاریف کلاسها، فضای نام دیگری را در محدوده‌ی محلی قرار می‌دهند." #: ../../tutorial/classes.rst:138 msgid "" -"It is important to realize that scopes are determined textually: the global " -"scope of a function defined in a module is that module's namespace, no " -"matter from where or by what alias the function is called. On the other " -"hand, the actual search for names is done dynamically, at run time --- " -"however, the language definition is evolving towards static name resolution, " -"at \"compile\" time, so don't rely on dynamic name resolution! (In fact, " -"local variables are already determined statically.)" -msgstr "" -"درک این نکته مهم است که محدوده‌ها به‌صورت متنی (بر اساس جایگاه در کد) تعیین می‌شوند: محدوده‌ی سراسری " -"تابعی که در یک ماژول تعریف شده است، همان فضای نام آن ماژول است، " -"فرقی نمی‌کند که تابع از کجا یا با چه نام مستعاری فراخوانی شود. از سوی " -"دیگر، جستجوی واقعی برای نام‌ها به‌صورت پویا (داینامیک) و در زمان اجرا انجام می‌شود --- " -"با این حال، تعریف زبان به سمت و سوی حلِ ایستا (استاتیک) نام‌ها در زمان «کامپایل» پیش می‌رود، " -"پس به حلِ پویای نام‌ها اعتماد نکنید! (در واقع، متغیرهای محلی از قبل به‌صورت ایستا تعیین می‌شوند.)" +"It is important to realize that scopes are determined textually: the global scope of a function defined in a module is that module's namespace, no matter from where " +"or by what alias the function is called. On the other hand, the actual search for names is done dynamically, at run time --- however, the language definition is " +"evolving towards static name resolution, at \"compile\" time, so don't rely on dynamic name resolution! (In fact, local variables are already determined " +"statically.)" +msgstr "" +"درک این نکته مهم است که محدوده‌ها به‌صورت متنی (بر اساس جایگاه در کد) تعیین می‌شوند: محدوده‌ی سراسری تابعی که در یک ماژول تعریف شده است، همان فضای نام آن ماژول است، " +"فرقی نمی‌کند که تابع از کجا یا با چه نام مستعاری فراخوانی شود. از سوی دیگر، جستجوی واقعی برای نام‌ها به‌صورت پویا (داینامیک) و در زمان اجرا انجام می‌شود --- با این حال، " +"تعریف زبان به سمت و سوی حلِ ایستا (استاتیک) نام‌ها در زمان «کامپایل» پیش می‌رود، پس به حلِ پویای نام‌ها اعتماد نکنید! (در واقع، متغیرهای محلی از قبل به‌صورت ایستا تعیین " +"می‌شوند.)" #: ../../tutorial/classes.rst:146 msgid "" -"A special quirk of Python is that -- if no :keyword:`global` " -"or :keyword:`nonlocal` statement is in effect -- assignments to names always " -"go into the innermost scope. Assignments do not copy data --- they just bind " -"names to objects. The same is true for deletions: the statement ``del x`` " -"removes the binding of ``x`` from the namespace referenced by the local " -"scope. In fact, all operations that introduce new names use the local " -"scope: in particular, :keyword:`import` statements and function definitions " -"bind the module or function name in the local scope." -msgstr "" -"یک ویژگی خاص پایتون این است که --- اگر دستور :keyword:`global` " -"یا :keyword:`nonlocal` فعال نباشد --- تخصیص‌های (مقداردهی‌های) نام‌ها همیشه " -"به درونی‌ترین محدوده (محلی‌ترین) می‌روند. تخصیص‌ها داده‌ها را کپی نمی‌کنند --- " -"بلکه فقط نام‌ها را به اشیاء متصل می‌کنند. همین موضوع در مورد حذف‌ها نیز صادق است: " -"دستور ``del x`` اتصال ``x`` را از فضای نامی که توسط محدوده‌ی محلی ارجاع داده شده است، حذف می‌کند. " -"در واقع، تمام عملیاتی که نام‌های جدیدی معرفی می‌کنند از محدوده‌ی محلی استفاده می‌کنند: " -"به‌ویژه، دستورات :keyword:`import` و تعاریف توابع، نام ماژول یا تابع را در محدوده‌ی محلی متصل می‌کنند." +"A special quirk of Python is that -- if no :keyword:`global` or :keyword:`nonlocal` statement is in effect -- assignments to names always go into the innermost " +"scope. Assignments do not copy data --- they just bind names to objects. The same is true for deletions: the statement ``del x`` removes the binding of ``x`` from " +"the namespace referenced by the local scope. In fact, all operations that introduce new names use the local scope: in particular, :keyword:`import` statements and " +"function definitions bind the module or function name in the local scope." +msgstr "" +"یک ویژگی خاص پایتون این است که --- اگر دستور :keyword:`global` یا :keyword:`nonlocal` فعال نباشد --- تخصیص‌های (مقداردهی‌های) نام‌ها همیشه به درونی‌ترین محدوده " +"(محلی‌ترین) می‌روند. تخصیص‌ها داده‌ها را کپی نمی‌کنند --- بلکه فقط نام‌ها را به اشیاء متصل می‌کنند. همین موضوع در مورد حذف‌ها نیز صادق است: دستور ``del x`` اتصال ``x`` را " +"از فضای نامی که توسط محدوده‌ی محلی ارجاع داده شده است، حذف می‌کند. در واقع، تمام عملیاتی که نام‌های جدیدی معرفی می‌کنند از محدوده‌ی محلی استفاده می‌کنند: به‌ویژه، " +"دستورات :keyword:`import` و تعاریف توابع، نام ماژول یا تابع را در محدوده‌ی محلی متصل می‌کنند." #: ../../tutorial/classes.rst:154 msgid "" -"The :keyword:`global` statement can be used to indicate that particular " -"variables live in the global scope and should be rebound there; " -"the :keyword:`nonlocal` statement indicates that particular variables live " -"in an enclosing scope and should be rebound there." +"The :keyword:`global` statement can be used to indicate that particular variables live in the global scope and should be rebound there; the :keyword:`nonlocal` " +"statement indicates that particular variables live in an enclosing scope and should be rebound there." msgstr "" -"از دستور :keyword:`global` می‌توان برای نشان دادن این استفاده کرد که متغیرهای خاصی " -"در محدوده‌ی سراسری قرار دارند و باید در همان محدوده دوباره متصل شوند؛ " -"دستور :keyword:`nonlocal` نشان می‌دهد که متغیرهای خاصی در یک محدوده‌ی محاط‌شونده قرار دارند " -"و باید در آن محدوده دوباره متصل شوند." +"از دستور :keyword:`global` می‌توان برای نشان دادن این استفاده کرد که متغیرهای خاصی در محدوده‌ی سراسری قرار دارند و باید در همان محدوده دوباره متصل شوند؛ " +"دستور :keyword:`nonlocal` نشان می‌دهد که متغیرهای خاصی در یک محدوده‌ی محاط‌شونده قرار دارند و باید در آن محدوده دوباره متصل شوند." #: ../../tutorial/classes.rst:162 msgid "Scopes and Namespaces Example" @@ -379,13 +255,8 @@ msgstr "مثال محدوده‌ها و فضای نام‌ها" #: ../../tutorial/classes.rst:164 msgid "" -"This is an example demonstrating how to reference the different scopes and " -"namespaces, and how :keyword:`global` and :keyword:`nonlocal` affect " -"variable binding::" -msgstr "" -"این مثالی است که نحوه‌ی ارجاع به محدوده‌ها و فضای نام‌های مختلف، و تأثیر " -"دستورات :keyword:`global` و :keyword:`nonlocal` بر اتصال متغیرها را نشان " -"می‌دهد::" +"This is an example demonstrating how to reference the different scopes and namespaces, and how :keyword:`global` and :keyword:`nonlocal` affect variable binding::" +msgstr "این مثالی است که نحوه‌ی ارجاع به محدوده‌ها و فضای نام‌های مختلف، و تأثیر دستورات :keyword:`global` و :keyword:`nonlocal` بر اتصال متغیرها را نشان می‌دهد::" #: ../../tutorial/classes.rst:168 msgid "" @@ -453,34 +324,23 @@ msgstr "" #: ../../tutorial/classes.rst:200 msgid "" -"Note how the *local* assignment (which is default) didn't change " -"*scope_test*\\'s binding of *spam*. The :keyword:`nonlocal` assignment " -"changed *scope_test*\\'s binding of *spam*, and the :keyword:`global` " -"assignment changed the module-level binding." +"Note how the *local* assignment (which is default) didn't change *scope_test*\\'s binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\\'s " +"binding of *spam*, and the :keyword:`global` assignment changed the module-level binding." msgstr "" -"توجه کنید که تخصیص *محلی* (که به‌صورت پیش‌فرض است)، اتصال *spam* را در " -"*scope_test* تغییر نداد. تخصیص :keyword:`nonlocal`، اتصال *spam* را در " -"*scope_test* تغییر داد، و تخصیص :keyword:`global`، اتصال را در سطح ماژول تغییر داد." +"توجه کنید که تخصیص *محلی* (که به‌صورت پیش‌فرض است)، اتصال *spam* را در *scope_test* تغییر نداد. تخصیص :keyword:`nonlocal`، اتصال *spam* را در *scope_test* تغییر داد، " +"و تخصیص :keyword:`global`، اتصال را در سطح ماژول تغییر داد." #: ../../tutorial/classes.rst:205 -msgid "" -"You can also see that there was no previous binding for *spam* before " -"the :keyword:`global` assignment." -msgstr "" -"همچنین می‌توانید ببینید که قبل از تخصیص :keyword:`global`، هیچ اتصال قبلی برای *spam* " -"وجود نداشت." +msgid "You can also see that there was no previous binding for *spam* before the :keyword:`global` assignment." +msgstr "همچنین می‌توانید ببینید که قبل از تخصیص :keyword:`global`، هیچ اتصال قبلی برای *spam* وجود نداشت." #: ../../tutorial/classes.rst:212 msgid "A First Look at Classes" msgstr "در نگاه اول به کلاسها" #: ../../tutorial/classes.rst:214 -msgid "" -"Classes introduce a little bit of new syntax, three new object types, and " -"some new semantics." -msgstr "" -"کلاسها کمی نحو جدید، سه نوع شیء جدید، و " -"مفاهیم معنایی جدیدی را معرفی می‌کنند." +msgid "Classes introduce a little bit of new syntax, three new object types, and some new semantics." +msgstr "کلاسها کمی نحو جدید، سه نوع شیء جدید، و مفاهیم معنایی جدیدی را معرفی می‌کنند." #: ../../tutorial/classes.rst:221 msgid "Class Definition Syntax" @@ -508,80 +368,54 @@ msgstr "" #: ../../tutorial/classes.rst:232 msgid "" -"Class definitions, like function definitions (:keyword:`def` statements) " -"must be executed before they have any effect. (You could conceivably place " -"a class definition in a branch of an :keyword:`if` statement, or inside a " -"function.)" +"Class definitions, like function definitions (:keyword:`def` statements) must be executed before they have any effect. (You could conceivably place a class " +"definition in a branch of an :keyword:`if` statement, or inside a function.)" msgstr "" -"تعاریف کلاسها، مانند تعاریف توابع (دستورات :keyword:`def`)، " -"باید قبل از اینکه تأثیری داشته باشند، اجرا شوند. (به‌طور تئوری می‌توانید " -"یک تعریف کلاس را در یک شاخه از دستور :keyword:`if` یا داخل یک تابع قرار دهید.)" +"تعاریف کلاسها، مانند تعاریف توابع (دستورات :keyword:`def`)، باید قبل از اینکه تأثیری داشته باشند، اجرا شوند. (به‌طور تئوری می‌توانید یک تعریف کلاس را در یک شاخه از " +"دستور :keyword:`if` یا داخل یک تابع قرار دهید.)" #: ../../tutorial/classes.rst:236 msgid "" -"In practice, the statements inside a class definition will usually be " -"function definitions, but other statements are allowed, and sometimes useful " -"--- we'll come back to this later. The function definitions inside a class " -"normally have a peculiar form of argument list, dictated by the calling " -"conventions for methods --- again, this is explained later." +"In practice, the statements inside a class definition will usually be function definitions, but other statements are allowed, and sometimes useful --- we'll come " +"back to this later. The function definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods --- " +"again, this is explained later." msgstr "" -"در عمل، دستورات داخل یک تعریف کلاس معمولاً تعاریف توابع هستند، اما دستورات دیگری نیز مجاز هستند و گاهی مفیدند " -"--- بعداً به این موضوع بازخواهیم گشت. تعاریف توابع داخل یک کلاس " -"معمولاً دارای شکل خاصی از لیست آرگومان‌ها هستند که توسط قراردادهای فراخوانی برای متدها تعیین می‌شود " -"--- باز هم، این موضوع بعداً توضیح داده می‌شود." +"در عمل، دستورات داخل یک تعریف کلاس معمولاً تعاریف توابع هستند، اما دستورات دیگری نیز مجاز هستند و گاهی مفیدند --- بعداً به این موضوع بازخواهیم گشت. تعاریف توابع داخل " +"یک کلاس معمولاً دارای شکل خاصی از لیست آرگومان‌ها هستند که توسط قراردادهای فراخوانی برای متدها تعیین می‌شود --- باز هم، این موضوع بعداً توضیح داده می‌شود." #: ../../tutorial/classes.rst:242 msgid "" -"When a class definition is entered, a new namespace is created, and used as " -"the local scope --- thus, all assignments to local variables go into this " -"new namespace. In particular, function definitions bind the name of the new " -"function here." +"When a class definition is entered, a new namespace is created, and used as the local scope --- thus, all assignments to local variables go into this new " +"namespace. In particular, function definitions bind the name of the new function here." msgstr "" -"هنگامی که یک تعریف کلاس وارد می‌شود، یک فضای نام جدید ایجاد شده و به‌عنوان " -"محدوده‌ی محلی استفاده می‌شود --- بنابراین، تمام تخصیص‌ها به متغیرهای محلی به این " -"فضای نام جدید می‌روند. به‌ویژه، تعاریف توابع، نام تابع جدید را در اینجا " -"متصل می‌کنند." +"هنگامی که یک تعریف کلاس وارد می‌شود، یک فضای نام جدید ایجاد شده و به‌عنوان محدوده‌ی محلی استفاده می‌شود --- بنابراین، تمام تخصیص‌ها به متغیرهای محلی به این فضای نام جدید " +"می‌روند. به‌ویژه، تعاریف توابع، نام تابع جدید را در اینجا متصل می‌کنند." #: ../../tutorial/classes.rst:247 msgid "" -"When a class definition is left normally (via the end), a *class object* is " -"created. This is basically a wrapper around the contents of the namespace " -"created by the class definition; we'll learn more about class objects in the " -"next section. The original local scope (the one in effect just before the " -"class definition was entered) is reinstated, and the class object is bound " -"here to the class name given in the class definition header (:class:`!" -"ClassName` in the example)." -msgstr "" -"هنگامی که یک تعریف کلاس به‌طور عادی (با رسیدن به انتها) ترک می‌شود، یک *شیء کلاس* " -"ایجاد می‌شود. این در اصل یک پوسته (wrapper) پیرامون محتویات فضای نامی است که " -"توسط تعریف کلاس ایجاد شده است؛ در بخش بعدی بیشتر درباره‌ی اشیاء کلاس خواهیم آموخت. " -"محدوده‌ی محلی اصلی (همان محدوده‌ای که درست قبل از ورود به تعریف کلاس فعال بود) " -"بازیابی می‌شود، و شیء کلاس در اینجا به نام کلاسی که در سرآیند تعریف کلاس داده شده است، متصل می‌شود " -"(:class:`!ClassName` در مثال)." +"When a class definition is left normally (via the end), a *class object* is created. This is basically a wrapper around the contents of the namespace created by " +"the class definition; we'll learn more about class objects in the next section. The original local scope (the one in effect just before the class definition was " +"entered) is reinstated, and the class object is bound here to the class name given in the class definition header (:class:`!ClassName` in the example)." +msgstr "" +"هنگامی که یک تعریف کلاس به‌طور عادی (با رسیدن به انتها) ترک می‌شود، یک *شیء کلاس* ایجاد می‌شود. این در اصل یک پوسته (wrapper) پیرامون محتویات فضای نامی است که توسط " +"تعریف کلاس ایجاد شده است؛ در بخش بعدی بیشتر درباره‌ی اشیاء کلاس خواهیم آموخت. محدوده‌ی محلی اصلی (همان محدوده‌ای که درست قبل از ورود به تعریف کلاس فعال بود) بازیابی " +"می‌شود، و شیء کلاس در اینجا به نام کلاسی که در سرآیند تعریف کلاس داده شده است، متصل می‌شود (:class:`!ClassName` در مثال)." #: ../../tutorial/classes.rst:259 msgid "Class Objects" msgstr "اشیاء کلاس" #: ../../tutorial/classes.rst:261 -msgid "" -"Class objects support two kinds of operations: attribute references and " -"instantiation." -msgstr "" -"اشیاء کلاس از دو نوع عملیات پشتیبانی می‌کنند: ارجاع به ویژگیها و " -"نمونه‌سازی." +msgid "Class objects support two kinds of operations: attribute references and instantiation." +msgstr "اشیاء کلاس از دو نوع عملیات پشتیبانی می‌کنند: ارجاع به ویژگیها و نمونه‌سازی." #: ../../tutorial/classes.rst:264 msgid "" -"*Attribute references* use the standard syntax used for all attribute " -"references in Python: ``obj.name``. Valid attribute names are all the names " -"that were in the class's namespace when the class object was created. So, " -"if the class definition looked like this::" +"*Attribute references* use the standard syntax used for all attribute references in Python: ``obj.name``. Valid attribute names are all the names that were in the " +"class's namespace when the class object was created. So, if the class definition looked like this::" msgstr "" -"*ارجاع به ویژگیها* از همان دستور زبان استاندارد که برای همه‌ی ارجاعها " -"به ویژگیها در پایتون استفاده می‌شود، پیروی می‌کند: ``obj.name``. نام‌های ویژگی معتبر، " -"همه‌ی نام‌هایی هستند که در هنگام ایجاد شیء کلاس، در فضای نام آن کلاس وجود داشته‌اند. " -"بنابراین، اگر تعریف کلاس به این شکل بود::" +"*ارجاع به ویژگیها* از همان دستور زبان استاندارد که برای همه‌ی ارجاعها به ویژگیها در پایتون استفاده می‌شود، پیروی می‌کند: ``obj.name``. نام‌های ویژگی معتبر، همه‌ی نام‌هایی " +"هستند که در هنگام ایجاد شیء کلاس، در فضای نام آن کلاس وجود داشته‌اند. بنابراین، اگر تعریف کلاس به این شکل بود::" #: ../../tutorial/classes.rst:269 msgid "" @@ -601,50 +435,37 @@ msgstr "" #: ../../tutorial/classes.rst:276 msgid "" -"then ``MyClass.i`` and ``MyClass.f`` are valid attribute references, " -"returning an integer and a function object, respectively. Class attributes " -"can also be assigned to, so you can change the value of ``MyClass.i`` by " -"assignment. :attr:`~type.__doc__` is also a valid attribute, returning the " -"docstring belonging to the class: ``\"A simple example class\"``." +"then ``MyClass.i`` and ``MyClass.f`` are valid attribute references, returning an integer and a function object, respectively. Class attributes can also be assigned " +"to, so you can change the value of ``MyClass.i`` by assignment. :attr:`~type.__doc__` is also a valid attribute, returning the docstring belonging to the class: " +"``\"A simple example class\"``." msgstr "" -"سپس ``MyClass.i`` و ``MyClass.f`` ارجاعهای ویژگی معتبری هستند که به‌ترتیب یک عدد صحیح و یک شیء تابع را برمی‌گردانند. " -"به ویژگیهای کلاس نیز می‌توان مقدار داد، بنابراین می‌توانید مقدار ``MyClass.i`` را با تخصیص (مقداردهی) تغییر دهید. " -":attr:`~type.__doc__` نیز یک ویژگی معتبر است که رشته‌ی مستند (docstring) متعلق به کلاس را برمی‌گرداند: " +"سپس ``MyClass.i`` و ``MyClass.f`` ارجاعهای ویژگی معتبری هستند که به‌ترتیب یک عدد صحیح و یک شیء تابع را برمی‌گردانند. به ویژگیهای کلاس نیز می‌توان مقدار داد، بنابراین " +"می‌توانید مقدار ``MyClass.i`` را با تخصیص (مقداردهی) تغییر دهید. :attr:`~type.__doc__` نیز یک ویژگی معتبر است که رشته‌ی مستند (docstring) متعلق به کلاس را برمی‌گرداند: " "``\"A simple example class\"``." #: ../../tutorial/classes.rst:282 msgid "" -"Class *instantiation* uses function notation. Just pretend that the class " -"object is a parameterless function that returns a new instance of the class. " -"For example (assuming the above class)::" +"Class *instantiation* uses function notation. Just pretend that the class object is a parameterless function that returns a new instance of the class. For example " +"(assuming the above class)::" msgstr "" -"*نمونه‌سازی* کلاس از نماد توابع استفاده می‌کند. " -"فقط تصور کنید که شیء کلاس، یک تابع بدون پارامتر است که یک نمونه‌ی جدید از کلاس را برمی‌گرداند. " -"برای مثال (با فرض کلاس بالا)::" +"*نمونه‌سازی* کلاس از نماد توابع استفاده می‌کند. فقط تصور کنید که شیء کلاس، یک تابع بدون پارامتر است که یک نمونه‌ی جدید از کلاس را برمی‌گرداند. برای مثال (با فرض کلاس " +"بالا)::" #: ../../tutorial/classes.rst:286 ../../tutorial/classes.rst:303 msgid "x = MyClass()" msgstr "x = MyClass()" #: ../../tutorial/classes.rst:288 -msgid "" -"creates a new *instance* of the class and assigns this object to the local " -"variable ``x``." -msgstr "" -"یک *نمونه* جدید از کلاس ایجاد می‌کند و این شیء را به متغیر محلی " -"``x`` تخصیص می‌دهد." +msgid "creates a new *instance* of the class and assigns this object to the local variable ``x``." +msgstr "یک *نمونه* جدید از کلاس ایجاد می‌کند و این شیء را به متغیر محلی ``x`` تخصیص می‌دهد." #: ../../tutorial/classes.rst:291 msgid "" -"The instantiation operation (\"calling\" a class object) creates an empty " -"object. Many classes like to create objects with instances customized to a " -"specific initial state. Therefore a class may define a special method " -"named :meth:`~object.__init__`, like this::" +"The instantiation operation (\"calling\" a class object) creates an empty object. Many classes like to create objects with instances customized to a specific " +"initial state. Therefore a class may define a special method named :meth:`~object.__init__`, like this::" msgstr "" -"عملیات نمونه‌سازی (که «فراخوانی» یک شیء کلاس است) یک شیء خالی ایجاد می‌کند. " -"بسیاری از کلاسها ترجیح می‌دهند اشیایی با نمونه‌هایی ایجاد کنند که به یک حالت اولیه‌ی خاص سفارشی‌سازی شده‌اند. " -"بنابراین، یک کلاس ممکن است یک متد ویژه به نام :meth:`~object.__init__` تعریف کند، " -"مانند این::" +"عملیات نمونه‌سازی (که «فراخوانی» یک شیء کلاس است) یک شیء خالی ایجاد می‌کند. بسیاری از کلاسها ترجیح می‌دهند اشیایی با نمونه‌هایی ایجاد کنند که به یک حالت اولیه‌ی خاص " +"سفارشی‌سازی شده‌اند. بنابراین، یک کلاس ممکن است یک متد ویژه به نام :meth:`~object.__init__` تعریف کند، مانند این::" #: ../../tutorial/classes.rst:296 msgid "" @@ -656,25 +477,19 @@ msgstr "" #: ../../tutorial/classes.rst:299 msgid "" -"When a class defines an :meth:`~object.__init__` method, class instantiation " -"automatically invokes :meth:`!__init__` for the newly created class " -"instance. So in this example, a new, initialized instance can be obtained " -"by::" +"When a class defines an :meth:`~object.__init__` method, class instantiation automatically invokes :meth:`!__init__` for the newly created class instance. So in " +"this example, a new, initialized instance can be obtained by::" msgstr "" -"وقتی یک کلاس یک متد :meth:`~object.__init__` تعریف می‌کند، نمونه‌سازی کلاس " -"به‌طور خودکار :meth:`!__init__` را برای نمونه‌ی تازه‌ایجادشده‌ی کلاس فراخوانی می‌کند. " -"بنابراین در این مثال، می‌توان یک نمونه‌ی جدید و مقداردهی‌شده را با دستور زیر " -"به‌دست آورد::" +"وقتی یک کلاس یک متد :meth:`~object.__init__` تعریف می‌کند، نمونه‌سازی کلاس به‌طور خودکار :meth:`!__init__` را برای نمونه‌ی تازه‌ایجادشده‌ی کلاس فراخوانی می‌کند. بنابراین " +"در این مثال، می‌توان یک نمونه‌ی جدید و مقداردهی‌شده را با دستور زیر به‌دست آورد::" #: ../../tutorial/classes.rst:305 msgid "" -"Of course, the :meth:`~object.__init__` method may have arguments for " -"greater flexibility. In that case, arguments given to the class " -"instantiation operator are passed on to :meth:`!__init__`. For example, ::" +"Of course, the :meth:`~object.__init__` method may have arguments for greater flexibility. In that case, arguments given to the class instantiation operator are " +"passed on to :meth:`!__init__`. For example, ::" msgstr "" -"البته، متد :meth:`~object.__init__` ممکن است برای انعطاف‌پذیری بیشتر، آرگومان‌هایی داشته باشد. " -"در آن صورت، آرگومان‌هایی که به عملگر نمونه‌سازی کلاس داده می‌شوند، به :meth:`!__init__` منتقل می‌شوند. " -"برای مثال، ::" +"البته، متد :meth:`~object.__init__` ممکن است برای انعطاف‌پذیری بیشتر، آرگومان‌هایی داشته باشد. در آن صورت، آرگومان‌هایی که به عملگر نمونه‌سازی کلاس داده می‌شوند، " +"به :meth:`!__init__` منتقل می‌شوند. برای مثال، ::" #: ../../tutorial/classes.rst:309 msgid "" @@ -702,28 +517,21 @@ msgstr "اشیاء نمونه" #: ../../tutorial/classes.rst:324 msgid "" -"Now what can we do with instance objects? The only operations understood by " -"instance objects are attribute references. There are two kinds of valid " -"attribute names: data attributes and methods." +"Now what can we do with instance objects? The only operations understood by instance objects are attribute references. There are two kinds of valid attribute " +"names: data attributes and methods." msgstr "" -"حالا با اشیاء نمونه چه کاری می‌توانیم انجام دهیم؟ تنها عملیاتی که اشیاء نمونه " -"می‌فهمند، ارجاع به ویژگیها (attribute references) است. دو نوع نام ویژگی معتبر وجود دارد: " +"حالا با اشیاء نمونه چه کاری می‌توانیم انجام دهیم؟ تنها عملیاتی که اشیاء نمونه می‌فهمند، ارجاع به ویژگیها (attribute references) است. دو نوع نام ویژگی معتبر وجود دارد: " "ویژگیهای داده (data attributes) و متدها (methods)." #: ../../tutorial/classes.rst:328 msgid "" -"*Data attributes* correspond to \"instance variables\" in Smalltalk, and to " -"\"data members\" in C++. Data attributes need not be declared; like local " -"variables, they spring into existence when they are first assigned to. For " -"example, if ``x`` is the instance of :class:`!MyClass` created above, the " -"following piece of code will print the value ``16``, without leaving a " -"trace::" +"*Data attributes* correspond to \"instance variables\" in Smalltalk, and to \"data members\" in C++. Data attributes need not be declared; like local variables, " +"they spring into existence when they are first assigned to. For example, if ``x`` is the instance of :class:`!MyClass` created above, the following piece of code " +"will print the value ``16``, without leaving a trace::" msgstr "" -"*ویژگیهای داده* معادل «متغیرهای نمونه» در زبان اسمالتاک و " -"«عضوهای داده» در ++C هستند. ویژگیهای داده نیازی به اعلام ندارند؛ مانند متغیرهای محلی، " -"هنگامی که برای اولین بار به آنها مقدار داده می‌شود، به‌وجود می‌آیند. برای " -"مثال، اگر ``x`` نمونه‌ای از :class:`!MyClass` باشد که در بالا ایجاد شده است، " -"قطعه کد زیر مقدار ``16`` را چاپ می‌کند، بدون اینکه هیچ اثری از خود بر جای بگذارد::" +"*ویژگیهای داده* معادل «متغیرهای نمونه» در زبان اسمالتاک و «عضوهای داده» در ++C هستند. ویژگیهای داده نیازی به اعلام ندارند؛ مانند متغیرهای محلی، هنگامی که برای اولین " +"بار به آنها مقدار داده می‌شود، به‌وجود می‌آیند. برای مثال، اگر ``x`` نمونه‌ای از :class:`!MyClass` باشد که در بالا ایجاد شده است، قطعه کد زیر مقدار ``16`` را چاپ می‌کند، " +"بدون اینکه هیچ اثری از خود بر جای بگذارد::" #: ../../tutorial/classes.rst:334 msgid "" @@ -740,27 +548,18 @@ msgstr "" "del x.counter" #: ../../tutorial/classes.rst:340 -msgid "" -"The other kind of instance attribute reference is a *method*. A method is a " -"function that \"belongs to\" an object." -msgstr "" -"نوع دیگر ارجاع به ویژگی نمونه، *متد* است. متد، تابعی است که " -"«به» یک شیء تعلق دارد." +msgid "The other kind of instance attribute reference is a *method*. A method is a function that \"belongs to\" an object." +msgstr "نوع دیگر ارجاع به ویژگی نمونه، *متد* است. متد، تابعی است که «به» یک شیء تعلق دارد." #: ../../tutorial/classes.rst:345 msgid "" -"Valid method names of an instance object depend on its class. By " -"definition, all attributes of a class that are function objects define " -"corresponding methods of its instances. So in our example, ``x.f`` is a " -"valid method reference, since ``MyClass.f`` is a function, but ``x.i`` is " -"not, since ``MyClass.i`` is not. But ``x.f`` is not the same thing as " -"``MyClass.f`` --- it is a *method object*, not a function object." +"Valid method names of an instance object depend on its class. By definition, all attributes of a class that are function objects define corresponding methods of " +"its instances. So in our example, ``x.f`` is a valid method reference, since ``MyClass.f`` is a function, but ``x.i`` is not, since ``MyClass.i`` is not. But " +"``x.f`` is not the same thing as ``MyClass.f`` --- it is a *method object*, not a function object." msgstr "" -"نام‌های متد معتبر یک شیء نمونه به کلاس آن بستگی دارد. طبق " -"تعریف، تمام ویژگیهای یک کلاس که شیء تابع هستند، متدهای متناظر با نمونه‌های آن را تعریف می‌کنند. " -"بنابراین در مثال ما، ``x.f`` یک ارجاع متد معتبر است، زیرا ``MyClass.f`` یک تابع است، اما ``x.i`` " -"معتبر نیست، زیرا ``MyClass.i`` تابع نیست. اما ``x.f`` با ``MyClass.f`` یکسان نیست --- " -"بلکه یک *شیء متد* است، نه یک شیء تابع." +"نام‌های متد معتبر یک شیء نمونه به کلاس آن بستگی دارد. طبق تعریف، تمام ویژگیهای یک کلاس که شیء تابع هستند، متدهای متناظر با نمونه‌های آن را تعریف می‌کنند. بنابراین در " +"مثال ما، ``x.f`` یک ارجاع متد معتبر است، زیرا ``MyClass.f`` یک تابع است، اما ``x.i`` معتبر نیست، زیرا ``MyClass.i`` تابع نیست. اما ``x.f`` با ``MyClass.f`` یکسان " +"نیست --- بلکه یک *شیء متد* است، نه یک شیء تابع." #: ../../tutorial/classes.rst:356 msgid "Method Objects" @@ -776,15 +575,11 @@ msgstr "x.f()" #: ../../tutorial/classes.rst:362 msgid "" -"If ``x = MyClass()``, as above, this will return the string ``'hello " -"world'``. However, it is not necessary to call a method right away: ``x.f`` " -"is a method object, and can be stored away and called at a later time. For " -"example::" +"If ``x = MyClass()``, as above, this will return the string ``'hello world'``. However, it is not necessary to call a method right away: ``x.f`` is a method object, " +"and can be stored away and called at a later time. For example::" msgstr "" -"اگر ``x = MyClass()``، همان‌طور که در بالا ذکر شد، این (فراخوانی) رشته‌ی ``'hello " -"world'`` را برمی‌گرداند. با این حال، لزومی ندارد که یک متد بلافاصله فراخوانی شود: ``x.f`` " -"یک شیء متد است و می‌توان آن را ذخیره کرده و در زمان دیگری فراخوانی کرد. " -"برای مثال::" +"اگر ``x = MyClass()``، همان‌طور که در بالا ذکر شد، این (فراخوانی) رشته‌ی ``'hello world'`` را برمی‌گرداند. با این حال، لزومی ندارد که یک متد بلافاصله فراخوانی شود: " +"``x.f`` یک شیء متد است و می‌توان آن را ذخیره کرده و در زمان دیگری فراخوانی کرد. برای مثال::" #: ../../tutorial/classes.rst:366 msgid "" @@ -802,51 +597,34 @@ msgstr "تا پایان زمان به چاپ ``hello world`` ادامه می‌ #: ../../tutorial/classes.rst:372 msgid "" -"What exactly happens when a method is called? You may have noticed that " -"``x.f()`` was called without an argument above, even though the function " -"definition for :meth:`!f` specified an argument. What happened to the " -"argument? Surely Python raises an exception when a function that requires an " -"argument is called without any --- even if the argument isn't actually " -"used..." +"What exactly happens when a method is called? You may have noticed that ``x.f()`` was called without an argument above, even though the function definition " +"for :meth:`!f` specified an argument. What happened to the argument? Surely Python raises an exception when a function that requires an argument is called without " +"any --- even if the argument isn't actually used..." msgstr "" -"دقیقاً وقتی یک متد فراخوانی می‌شود، چه اتفاقی می‌افتد؟ احتمالاً متوجه شده‌اید که " -"``x.f()`` در بالا بدون هیچ آرگومانی فراخوانی شد، حتی اگر تعریف تابع :meth:`!f` یک آرگومان را مشخص کرده بود. " -"چه بر سر آن آرگومان آمد؟ مسلماً پایتون وقتی یک تابع که به آرگومان نیاز دارد، بدون هیچ آرگومانی فراخوانی می‌شود، یک استثنا ایجاد می‌کند --- حتی اگر آن آرگومان واقعاً " -"استفاده نشود..." +"دقیقاً وقتی یک متد فراخوانی می‌شود، چه اتفاقی می‌افتد؟ احتمالاً متوجه شده‌اید که ``x.f()`` در بالا بدون هیچ آرگومانی فراخوانی شد، حتی اگر تعریف تابع :meth:`!f` یک " +"آرگومان را مشخص کرده بود. چه بر سر آن آرگومان آمد؟ مسلماً پایتون وقتی یک تابع که به آرگومان نیاز دارد، بدون هیچ آرگومانی فراخوانی می‌شود، یک استثنا ایجاد می‌کند --- " +"حتی اگر آن آرگومان واقعاً استفاده نشود..." #: ../../tutorial/classes.rst:378 msgid "" -"Actually, you may have guessed the answer: the special thing about methods " -"is that the instance object is passed as the first argument of the " -"function. In our example, the call ``x.f()`` is exactly equivalent to " -"``MyClass.f(x)``. In general, calling a method with a list of *n* arguments " -"is equivalent to calling the corresponding function with an argument list " -"that is created by inserting the method's instance object before the first " -"argument." +"Actually, you may have guessed the answer: the special thing about methods is that the instance object is passed as the first argument of the function. In our " +"example, the call ``x.f()`` is exactly equivalent to ``MyClass.f(x)``. In general, calling a method with a list of *n* arguments is equivalent to calling the " +"corresponding function with an argument list that is created by inserting the method's instance object before the first argument." msgstr "" -"در واقع، شاید پاسخ را حدس زده باشید: نکته‌ی ویژه در مورد متدها این است که " -"شیء نمونه به عنوان اولین آرگومان تابع ارسال می‌شود. در مثال ما، فراخوانی ``x.f()`` دقیقاً معادل " -"``MyClass.f(x)`` است. به طور کلی، فراخوانی یک متد با لیستی از *n* آرگومان " -"معادل فراخوانی تابع متناظر با لیست آرگومانی است که با قرار دادن شیء نمونه‌ی متد قبل از اولین آرگومان " -"ایجاد می‌شود." +"در واقع، شاید پاسخ را حدس زده باشید: نکته‌ی ویژه در مورد متدها این است که شیء نمونه به عنوان اولین آرگومان تابع ارسال می‌شود. در مثال ما، فراخوانی ``x.f()`` دقیقاً " +"معادل ``MyClass.f(x)`` است. به طور کلی، فراخوانی یک متد با لیستی از *n* آرگومان معادل فراخوانی تابع متناظر با لیست آرگومانی است که با قرار دادن شیء نمونه‌ی متد قبل " +"از اولین آرگومان ایجاد می‌شود." #: ../../tutorial/classes.rst:385 msgid "" -"In general, methods work as follows. When a non-data attribute of an " -"instance is referenced, the instance's class is searched. If the name " -"denotes a valid class attribute that is a function object, references to " -"both the instance object and the function object are packed into a method " -"object. When the method object is called with an argument list, a new " -"argument list is constructed from the instance object and the argument list, " -"and the function object is called with this new argument list." -msgstr "" -"به طور کلی، متدها به صورت زیر کار می‌کنند. هنگامی که به یک ویژگی غیرداده‌ای از یک " -"نمونه ارجاع داده می‌شود، کلاس آن نمونه جستجو می‌شود. اگر آن نام " -"نشان‌دهنده‌ی یک ویژگی کلاس معتبر باشد که یک شیء تابع است، ارجاعات به " -"هر دو شیء نمونه و شیء تابع در یک شیء متد بسته‌بندی " -"می‌شوند. هنگامی که شیء متد با یک لیست آرگومان فراخوانی می‌شود، یک لیست آرگومان جدید " -"از شیء نمونه و لیست آرگومان ساخته می‌شود و شیء تابع با این لیست آرگومان جدید " -"فراخوانی می‌شود." +"In general, methods work as follows. When a non-data attribute of an instance is referenced, the instance's class is searched. If the name denotes a valid class " +"attribute that is a function object, references to both the instance object and the function object are packed into a method object. When the method object is " +"called with an argument list, a new argument list is constructed from the instance object and the argument list, and the function object is called with this new " +"argument list." +msgstr "" +"به طور کلی، متدها به صورت زیر کار می‌کنند. هنگامی که به یک ویژگی غیرداده‌ای از یک نمونه ارجاع داده می‌شود، کلاس آن نمونه جستجو می‌شود. اگر آن نام نشان‌دهنده‌ی یک ویژگی " +"کلاس معتبر باشد که یک شیء تابع است، ارجاعات به هر دو شیء نمونه و شیء تابع در یک شیء متد بسته‌بندی می‌شوند. هنگامی که شیء متد با یک لیست آرگومان فراخوانی می‌شود، یک " +"لیست آرگومان جدید از شیء نمونه و لیست آرگومان ساخته می‌شود و شیء تابع با این لیست آرگومان جدید فراخوانی می‌شود." #: ../../tutorial/classes.rst:398 msgid "Class and Instance Variables" @@ -854,13 +632,8 @@ msgstr "کلاس و متغیر‌های نمونه" #: ../../tutorial/classes.rst:400 msgid "" -"Generally speaking, instance variables are for data unique to each instance " -"and class variables are for attributes and methods shared by all instances " -"of the class::" -msgstr "" -"به‌طور کلی، متغیرهای نمونه برای داده‌هایی هستند که مختص به هر نمونه " -"و متغیرهای کلاس برای ویژگیها و متدهایی هستند که بین همه‌ی نمونه‌ها " -"از آن کلاس مشترک هستند::" +"Generally speaking, instance variables are for data unique to each instance and class variables are for attributes and methods shared by all instances of the class::" +msgstr "به‌طور کلی، متغیرهای نمونه برای داده‌هایی هستند که مختص به هر نمونه و متغیرهای کلاس برای ویژگیها و متدهایی هستند که بین همه‌ی نمونه‌ها از آن کلاس مشترک هستند::" #: ../../tutorial/classes.rst:404 msgid "" @@ -902,17 +675,11 @@ msgstr "" #: ../../tutorial/classes.rst:422 msgid "" -"As discussed in :ref:`tut-object`, shared data can have possibly surprising " -"effects involving :term:`mutable` objects such as lists and dictionaries. " -"For example, the *tricks* list in the following code should not be used as a " -"class variable because just a single list would be shared by all *Dog* " -"instances::" +"As discussed in :ref:`tut-object`, shared data can have possibly surprising effects involving :term:`mutable` objects such as lists and dictionaries. For example, " +"the *tricks* list in the following code should not be used as a class variable because just a single list would be shared by all *Dog* instances::" msgstr "" -"همان‌طور که در :ref:`tut-object` بحث شد، داده‌های مشترک می‌توانند تأثیرات " -"شگفت‌آوری بر روی اشیاء :term:`mutable` مانند لیستها و دیکشنری‌ها داشته باشند. " -"برای مثال، لیست *tricks* در کد زیر نباید به‌عنوان یک " -"متغیر کلاس استفاده شود، زیرا فقط یک لیست واحد بین همه‌ی نمونه‌های *Dog* " -"مشترک خواهد بود::" +"همان‌طور که در :ref:`tut-object` بحث شد، داده‌های مشترک می‌توانند تأثیرات شگفت‌آوری بر روی اشیاء :term:`mutable` مانند لیستها و دیکشنری‌ها داشته باشند. برای مثال، لیست " +"*tricks* در کد زیر نباید به‌عنوان یک متغیر کلاس استفاده شود، زیرا فقط یک لیست واحد بین همه‌ی نمونه‌های *Dog* مشترک خواهد بود::" #: ../../tutorial/classes.rst:428 msgid "" @@ -997,12 +764,8 @@ msgid "Random Remarks" msgstr "نکات پراکنده" #: ../../tutorial/classes.rst:473 -msgid "" -"If the same attribute name occurs in both an instance and in a class, then " -"attribute lookup prioritizes the instance::" -msgstr "" -"اگر نام ویژگی مشابهی هم در یک نمونه و هم در یک کلاس وجود داشته باشد، آنگاه " -"جستجوی ویژگی، نمونه را اولویت‌بندی می‌کند::" +msgid "If the same attribute name occurs in both an instance and in a class, then attribute lookup prioritizes the instance::" +msgstr "اگر نام ویژگی مشابهی هم در یک نمونه و هم در یک کلاس وجود داشته باشد، آنگاه جستجوی ویژگی، نمونه را اولویت‌بندی می‌کند::" #: ../../tutorial/classes.rst:476 msgid "" @@ -1032,75 +795,51 @@ msgstr "" #: ../../tutorial/classes.rst:488 msgid "" -"Data attributes may be referenced by methods as well as by ordinary users " -"(\"clients\") of an object. In other words, classes are not usable to " -"implement pure abstract data types. In fact, nothing in Python makes it " -"possible to enforce data hiding --- it is all based upon convention. (On " -"the other hand, the Python implementation, written in C, can completely hide " -"implementation details and control access to an object if necessary; this " -"can be used by extensions to Python written in C.)" -msgstr "" -"ویژگیهای داده ممکن است هم توسط متدها و هم توسط کاربران عادی " -"(\"clients\") یک شیء ارجاع داده شوند. به عبارت دیگر، کلاسها برای " -"پیاده‌سازی انواع داده‌ی انتزاعی خالص قابل استفاده نیستند. در واقع، هیچ چیزی در پایتون " -"امکان اعمال پنهان‌سازی داده را فراهم نمی‌کند --- همه‌چیز بر اساس قرارداد است. (از " -"سوی دیگر، پیاده‌سازی پایتون که به زبان C نوشته شده است، می‌تواند جزئیات پیاده‌سازی را کاملاً پنهان کند " -"و در صورت نیاز دسترسی به یک شیء را کنترل کند؛ این " -"قابلیت می‌تواند توسط افزونه‌های پایتون که به زبان C نوشته می‌شوند، استفاده شود.)" +"Data attributes may be referenced by methods as well as by ordinary users (\"clients\") of an object. In other words, classes are not usable to implement pure " +"abstract data types. In fact, nothing in Python makes it possible to enforce data hiding --- it is all based upon convention. (On the other hand, the Python " +"implementation, written in C, can completely hide implementation details and control access to an object if necessary; this can be used by extensions to Python " +"written in C.)" +msgstr "" +"ویژگیهای داده ممکن است هم توسط متدها و هم توسط کاربران عادی (\"clients\") یک شیء ارجاع داده شوند. به عبارت دیگر، کلاسها برای پیاده‌سازی انواع داده‌ی انتزاعی خالص قابل " +"استفاده نیستند. در واقع، هیچ چیزی در پایتون امکان اعمال پنهان‌سازی داده را فراهم نمی‌کند --- همه‌چیز بر اساس قرارداد است. (از سوی دیگر، پیاده‌سازی پایتون که به زبان C " +"نوشته شده است، می‌تواند جزئیات پیاده‌سازی را کاملاً پنهان کند و در صورت نیاز دسترسی به یک شیء را کنترل کند؛ این قابلیت می‌تواند توسط افزونه‌های پایتون که به زبان C نوشته " +"می‌شوند، استفاده شود.)" #: ../../tutorial/classes.rst:496 msgid "" -"Clients should use data attributes with care --- clients may mess up " -"invariants maintained by the methods by stamping on their data attributes. " -"Note that clients may add data attributes of their own to an instance object " -"without affecting the validity of the methods, as long as name conflicts are " -"avoided --- again, a naming convention can save a lot of headaches here." +"Clients should use data attributes with care --- clients may mess up invariants maintained by the methods by stamping on their data attributes. Note that clients " +"may add data attributes of their own to an instance object without affecting the validity of the methods, as long as name conflicts are avoided --- again, a naming " +"convention can save a lot of headaches here." msgstr "" -"کاربران (clients) باید با احتیاط از ویژگیهای داده استفاده کنند --- کاربران ممکن است " -"ناورداهای حفظ‌شده توسط متدها را با دستکاری در ویژگیهای داده‌شان به هم بریزند. " -"توجه داشته باشید که کاربران ممکن است ویژگیهای داده‌ی خود را به یک شیء نمونه اضافه کنند " -"بدون اینکه بر صحت متدها تأثیر بگذارند، تا زمانی که تداخل نام‌ها " -"اجتناب شود --- باز هم، یک قرارداد نام‌گذاری می‌تواند از بسیاری از سردرگمی‌ها در اینجا جلوگیری کند." +"کاربران (clients) باید با احتیاط از ویژگیهای داده استفاده کنند --- کاربران ممکن است ناورداهای حفظ‌شده توسط متدها را با دستکاری در ویژگیهای داده‌شان به هم بریزند. توجه " +"داشته باشید که کاربران ممکن است ویژگیهای داده‌ی خود را به یک شیء نمونه اضافه کنند بدون اینکه بر صحت متدها تأثیر بگذارند، تا زمانی که تداخل نام‌ها اجتناب شود --- باز " +"هم، یک قرارداد نام‌گذاری می‌تواند از بسیاری از سردرگمی‌ها در اینجا جلوگیری کند." #: ../../tutorial/classes.rst:502 msgid "" -"There is no shorthand for referencing data attributes (or other methods!) " -"from within methods. I find that this actually increases the readability of " -"methods: there is no chance of confusing local variables and instance " -"variables when glancing through a method." +"There is no shorthand for referencing data attributes (or other methods!) from within methods. I find that this actually increases the readability of methods: " +"there is no chance of confusing local variables and instance variables when glancing through a method." msgstr "" -"هیچ گونه میان‌بری برای ارجاع به ویژگیهای داده (یا سایر متدها!) " -"از درون متدها وجود ندارد. به نظر من، این موضوع در واقع خوانایی " -"متدها را افزایش می‌دهد: هیچ شانسی برای اشتباه گرفتن متغیرهای محلی و متغیرهای " -"نمونه هنگام مرور سریع یک متد وجود ندارد." +"هیچ گونه میان‌بری برای ارجاع به ویژگیهای داده (یا سایر متدها!) از درون متدها وجود ندارد. به نظر من، این موضوع در واقع خوانایی متدها را افزایش می‌دهد: هیچ شانسی برای " +"اشتباه گرفتن متغیرهای محلی و متغیرهای نمونه هنگام مرور سریع یک متد وجود ندارد." #: ../../tutorial/classes.rst:507 msgid "" -"Often, the first argument of a method is called ``self``. This is nothing " -"more than a convention: the name ``self`` has absolutely no special meaning " -"to Python. Note, however, that by not following the convention your code " -"may be less readable to other Python programmers, and it is also conceivable " -"that a *class browser* program might be written that relies upon such a " -"convention." +"Often, the first argument of a method is called ``self``. This is nothing more than a convention: the name ``self`` has absolutely no special meaning to Python. " +"Note, however, that by not following the convention your code may be less readable to other Python programmers, and it is also conceivable that a *class browser* " +"program might be written that relies upon such a convention." msgstr "" -"معمولاً، اولین آرگومان یک متد ``self`` نامیده می‌شود. این " -"چیزی بیش از یک قرارداد نیست: نام ``self`` هیچ معنی خاصی " -"برای پایتون ندارد. با این حال، توجه داشته باشید که با رعایت نکردن این قرارداد، کد شما " -"ممکن است برای سایر برنامه‌نویسان پایتون کمتر خوانا باشد، و همچنین قابل‌تصور است " -"که یک برنامه *مرورگر کلاس* (class browser) نوشته شود که به چنین " -"قراردادی وابسته باشد." +"معمولاً، اولین آرگومان یک متد ``self`` نامیده می‌شود. این چیزی بیش از یک قرارداد نیست: نام ``self`` هیچ معنی خاصی برای پایتون ندارد. با این حال، توجه داشته باشید که " +"با رعایت نکردن این قرارداد، کد شما ممکن است برای سایر برنامه‌نویسان پایتون کمتر خوانا باشد، و همچنین قابل‌تصور است که یک برنامه *مرورگر کلاس* (class browser) نوشته " +"شود که به چنین قراردادی وابسته باشد." #: ../../tutorial/classes.rst:513 msgid "" -"Any function object that is a class attribute defines a method for instances " -"of that class. It is not necessary that the function definition is " -"textually enclosed in the class definition: assigning a function object to a " -"local variable in the class is also ok. For example::" +"Any function object that is a class attribute defines a method for instances of that class. It is not necessary that the function definition is textually enclosed " +"in the class definition: assigning a function object to a local variable in the class is also ok. For example::" msgstr "" -"هر شیء تابعی که یک ویژگی کلاس باشد، یک متد برای نمونه‌های " -"آن کلاس تعریف می‌کند. لازم نیست که تعریف تابع " -"لزوماً درون تعریف کلاس قرار داشته باشد: اختصاص یک شیء تابع به یک " -"متغیر محلی در کلاس نیز مجاز است. برای مثال::" +"هر شیء تابعی که یک ویژگی کلاس باشد، یک متد برای نمونه‌های آن کلاس تعریف می‌کند. لازم نیست که تعریف تابع لزوماً درون تعریف کلاس قرار داشته باشد: اختصاص یک شیء تابع به " +"یک متغیر محلی در کلاس نیز مجاز است. برای مثال::" #: ../../tutorial/classes.rst:518 msgid "" @@ -1130,23 +869,15 @@ msgstr "" #: ../../tutorial/classes.rst:530 msgid "" -"Now ``f``, ``g`` and ``h`` are all attributes of class :class:`!C` that " -"refer to function objects, and consequently they are all methods of " -"instances of :class:`!C` --- ``h`` being exactly equivalent to ``g``. Note " -"that this practice usually only serves to confuse the reader of a program." +"Now ``f``, ``g`` and ``h`` are all attributes of class :class:`!C` that refer to function objects, and consequently they are all methods of instances of :class:`!C` " +"--- ``h`` being exactly equivalent to ``g``. Note that this practice usually only serves to confuse the reader of a program." msgstr "" -"اکنون ``f``، ``g`` و ``h`` همگی ویژگیهای کلاس :class:`!C` هستند که " -"به اشیاء تابع اشاره دارند، و در نتیجه همگی متدهایی از " -"نمونه‌های :class:`!C` هستند --- ``h`` دقیقاً معادل ``g`` است. توجه " -"داشته باشید که این روش معمولاً فقط باعث سردرگمی خواننده‌ی برنامه می‌شود." +"اکنون ``f``، ``g`` و ``h`` همگی ویژگیهای کلاس :class:`!C` هستند که به اشیاء تابع اشاره دارند، و در نتیجه همگی متدهایی از نمونه‌های :class:`!C` هستند --- ``h`` دقیقاً " +"معادل ``g`` است. توجه داشته باشید که این روش معمولاً فقط باعث سردرگمی خواننده‌ی برنامه می‌شود." #: ../../tutorial/classes.rst:535 -msgid "" -"Methods may call other methods by using method attributes of the ``self`` " -"argument::" -msgstr "" -"متدها می‌توانند سایر متدها را با استفاده از ویژگیهای متد آرگومان ``self`` " -"فراخوانی کنند::" +msgid "Methods may call other methods by using method attributes of the ``self`` argument::" +msgstr "متدها می‌توانند سایر متدها را با استفاده از ویژگیهای متد آرگومان ``self`` فراخوانی کنند::" #: ../../tutorial/classes.rst:538 msgid "" @@ -1174,33 +905,20 @@ msgstr "" #: ../../tutorial/classes.rst:549 msgid "" -"Methods may reference global names in the same way as ordinary functions. " -"The global scope associated with a method is the module containing its " -"definition. (A class is never used as a global scope.) While one rarely " -"encounters a good reason for using global data in a method, there are many " -"legitimate uses of the global scope: for one thing, functions and modules " -"imported into the global scope can be used by methods, as well as functions " -"and classes defined in it. Usually, the class containing the method is " -"itself defined in this global scope, and in the next section we'll find some " -"good reasons why a method would want to reference its own class." -msgstr "" -"متدها ممکن است به نام‌های سراسری به همان روشی که توابع معمولی اشاره می‌کنند، ارجاع دهند. " -"محدوده‌ی سراسری مرتبط با یک متد، ماژولی است که شامل " -"تعریف آن است. (یک کلاس هرگز به عنوان محدوده‌ی سراسری استفاده نمی‌شود.) اگرچه به ندرت " -"دلیل خوبی برای استفاده از داده‌های سراسری در یک متد یافت می‌شود، اما کاربردهای " -"مشروع زیادی برای محدوده‌ی سراسری وجود دارد: برای یک چیز، توابع و ماژول‌هایی " -"که به محدوده‌ی سراسری ایمپورت شده‌اند، می‌توانند توسط متدها استفاده شوند، همچنین توابع " -"و کلاسهای تعریف‌شده در آن. معمولاً، کلاسی که شامل متد است، " -"خود در این محدوده‌ی سراسری تعریف می‌شود، و در بخش بعدی دلایل خوبی " -"خواهیم یافت که چرا یک متد ممکن است بخواهد به کلاس خودش ارجاع دهد." +"Methods may reference global names in the same way as ordinary functions. The global scope associated with a method is the module containing its definition. (A " +"class is never used as a global scope.) While one rarely encounters a good reason for using global data in a method, there are many legitimate uses of the global " +"scope: for one thing, functions and modules imported into the global scope can be used by methods, as well as functions and classes defined in it. Usually, the " +"class containing the method is itself defined in this global scope, and in the next section we'll find some good reasons why a method would want to reference its " +"own class." +msgstr "" +"متدها ممکن است به نام‌های سراسری به همان روشی که توابع معمولی اشاره می‌کنند، ارجاع دهند. محدوده‌ی سراسری مرتبط با یک متد، ماژولی است که شامل تعریف آن است. (یک کلاس " +"هرگز به عنوان محدوده‌ی سراسری استفاده نمی‌شود.) اگرچه به ندرت دلیل خوبی برای استفاده از داده‌های سراسری در یک متد یافت می‌شود، اما کاربردهای مشروع زیادی برای محدوده‌ی " +"سراسری وجود دارد: برای یک چیز، توابع و ماژول‌هایی که به محدوده‌ی سراسری ایمپورت شده‌اند، می‌توانند توسط متدها استفاده شوند، همچنین توابع و کلاسهای تعریف‌شده در آن. " +"معمولاً، کلاسی که شامل متد است، خود در این محدوده‌ی سراسری تعریف می‌شود، و در بخش بعدی دلایل خوبی خواهیم یافت که چرا یک متد ممکن است بخواهد به کلاس خودش ارجاع دهد." #: ../../tutorial/classes.rst:559 -msgid "" -"Each value is an object, and therefore has a *class* (also called its " -"*type*). It is stored as ``object.__class__``." -msgstr "" -"هر مقدار یک شیء است، و بنابراین دارای یک *کلاس* (که به آن " -"*تایپ* نیز گفته می‌شود) می‌باشد. این مقدار به‌صورت ``object.__class__`` ذخیره می‌شود." +msgid "Each value is an object, and therefore has a *class* (also called its *type*). It is stored as ``object.__class__``." +msgstr "هر مقدار یک شیء است، و بنابراین دارای یک *کلاس* (که به آن *تایپ* نیز گفته می‌شود) می‌باشد. این مقدار به‌صورت ``object.__class__`` ذخیره می‌شود." #: ../../tutorial/classes.rst:566 msgid "Inheritance" @@ -1208,13 +926,8 @@ msgstr "ارث‌بری" #: ../../tutorial/classes.rst:568 msgid "" -"Of course, a language feature would not be worthy of the name \"class\" " -"without supporting inheritance. The syntax for a derived class definition " -"looks like this::" -msgstr "" -"مسلماً، یک ویژگی زبانی بدون پشتیبانی از ارث‌بری، شایسته‌ی نام «کلاس» " -"نخواهد بود. نحو تعریف یک کلاس مشتق‌شده (derived class) " -"به این شکل است::" +"Of course, a language feature would not be worthy of the name \"class\" without supporting inheritance. The syntax for a derived class definition looks like this::" +msgstr "مسلماً، یک ویژگی زبانی بدون پشتیبانی از ارث‌بری، شایسته‌ی نام «کلاس» نخواهد بود. نحو تعریف یک کلاس مشتق‌شده (derived class) به این شکل است::" #: ../../tutorial/classes.rst:572 msgid "" @@ -1234,15 +947,11 @@ msgstr "" #: ../../tutorial/classes.rst:579 msgid "" -"The name :class:`!BaseClassName` must be defined in a namespace accessible " -"from the scope containing the derived class definition. In place of a base " -"class name, other arbitrary expressions are also allowed. This can be " -"useful, for example, when the base class is defined in another module::" +"The name :class:`!BaseClassName` must be defined in a namespace accessible from the scope containing the derived class definition. In place of a base class name, " +"other arbitrary expressions are also allowed. This can be useful, for example, when the base class is defined in another module::" msgstr "" -"نام :class:`!BaseClassName` باید در فضای نامی تعریف شده باشد که از " -"محدوده‌ای که شامل تعریف کلاس مشتق‌شده است، قابل دسترسی باشد. به جای نام " -"کلاس پایه، سایر عبارت‌های دلخواه نیز مجاز هستند. این " -"می‌تواند مفید باشد، برای مثال، زمانی که کلاس پایه در ماژول دیگری تعریف شده است::" +"نام :class:`!BaseClassName` باید در فضای نامی تعریف شده باشد که از محدوده‌ای که شامل تعریف کلاس مشتق‌شده است، قابل دسترسی باشد. به جای نام کلاس پایه، سایر عبارت‌های " +"دلخواه نیز مجاز هستند. این می‌تواند مفید باشد، برای مثال، زمانی که کلاس پایه در ماژول دیگری تعریف شده است::" #: ../../tutorial/classes.rst:585 msgid "class DerivedClassName(modname.BaseClassName):" @@ -1250,63 +959,42 @@ msgstr "class DerivedClassName(modname.BaseClassName):" #: ../../tutorial/classes.rst:587 msgid "" -"Execution of a derived class definition proceeds the same as for a base " -"class. When the class object is constructed, the base class is remembered. " -"This is used for resolving attribute references: if a requested attribute is " -"not found in the class, the search proceeds to look in the base class. This " -"rule is applied recursively if the base class itself is derived from some " -"other class." +"Execution of a derived class definition proceeds the same as for a base class. When the class object is constructed, the base class is remembered. This is used for " +"resolving attribute references: if a requested attribute is not found in the class, the search proceeds to look in the base class. This rule is applied recursively " +"if the base class itself is derived from some other class." msgstr "" -"اجرای تعریف یک کلاس مشتق‌شده به همان شیوه‌ای است که برای یک کلاس " -"پایه انجام می‌شود. هنگامی که شیء کلاس ساخته می‌شود، کلاس پایه به خاطر سپرده می‌شود. " -"این (اطلاعات) برای حل کردن ارجاعات به ویژگیها استفاده می‌شود: اگر ویژگی درخواستی " -"در کلاس یافت نشود، جستجو در کلاس پایه ادامه می‌یابد. این " -"قاعده به‌صورت بازگشتی اعمال می‌شود اگر خود کلاس پایه از کلاس " -"دیگری مشتق شده باشد." +"اجرای تعریف یک کلاس مشتق‌شده به همان شیوه‌ای است که برای یک کلاس پایه انجام می‌شود. هنگامی که شیء کلاس ساخته می‌شود، کلاس پایه به خاطر سپرده می‌شود. این (اطلاعات) برای " +"حل کردن ارجاعات به ویژگیها استفاده می‌شود: اگر ویژگی درخواستی در کلاس یافت نشود، جستجو در کلاس پایه ادامه می‌یابد. این قاعده به‌صورت بازگشتی اعمال می‌شود اگر خود کلاس " +"پایه از کلاس دیگری مشتق شده باشد." #: ../../tutorial/classes.rst:593 msgid "" -"There's nothing special about instantiation of derived classes: " -"``DerivedClassName()`` creates a new instance of the class. Method " -"references are resolved as follows: the corresponding class attribute is " -"searched, descending down the chain of base classes if necessary, and the " -"method reference is valid if this yields a function object." +"There's nothing special about instantiation of derived classes: ``DerivedClassName()`` creates a new instance of the class. Method references are resolved as " +"follows: the corresponding class attribute is searched, descending down the chain of base classes if necessary, and the method reference is valid if this yields a " +"function object." msgstr "" -"هیچ نکته‌ی خاصی درباره‌ی نمونه‌سازی کلاسهای مشتق‌شده وجود ندارد: " -"``DerivedClassName()`` یک نمونه‌ی جدید از کلاس ایجاد می‌کند. ارجاعهای متد " -"به‌صورت زیر حل می‌شوند: ویژگی کلاس متناظر " -"جستجو می‌شود، در صورت لزوم در زنجیره‌ی کلاسهای پایه به پایین می‌رود، و " -"ارجاع متد در صورتی معتبر است که این جستجو به یک شیء تابع منجر شود." +"هیچ نکته‌ی خاصی درباره‌ی نمونه‌سازی کلاسهای مشتق‌شده وجود ندارد: ``DerivedClassName()`` یک نمونه‌ی جدید از کلاس ایجاد می‌کند. ارجاعهای متد به‌صورت زیر حل می‌شوند: ویژگی " +"کلاس متناظر جستجو می‌شود، در صورت لزوم در زنجیره‌ی کلاسهای پایه به پایین می‌رود، و ارجاع متد در صورتی معتبر است که این جستجو به یک شیء تابع منجر شود." #: ../../tutorial/classes.rst:599 msgid "" -"Derived classes may override methods of their base classes. Because methods " -"have no special privileges when calling other methods of the same object, a " -"method of a base class that calls another method defined in the same base " -"class may end up calling a method of a derived class that overrides it. " -"(For C++ programmers: all methods in Python are effectively ``virtual``.)" +"Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a " +"base class that calls another method defined in the same base class may end up calling a method of a derived class that overrides it. (For C++ programmers: all " +"methods in Python are effectively ``virtual``.)" msgstr "" -"کلاسهای مشتق‌شده ممکن است متدهای کلاسهای پایه‌ی خود را بازنویسی کنند. از آنجایی که متدها " -"هنگام فراخوانی سایر متدهای همان شیء، امتیاز ویژه‌ای ندارند، یک " -"متد از یک کلاس پایه که متد دیگری را که در همان کلاس پایه تعریف شده فراخوانی می‌کند، ممکن است " -"در نهایت متدی از یک کلاس مشتق‌شده را فراخوانی کند که آن را بازنویسی کرده است. " -"(برای برنامه‌نویسان C++: تمام متدها در پایتون به‌طور مؤثر ``virtual`` هستند.)" +"کلاسهای مشتق‌شده ممکن است متدهای کلاسهای پایه‌ی خود را بازنویسی کنند. از آنجایی که متدها هنگام فراخوانی سایر متدهای همان شیء، امتیاز ویژه‌ای ندارند، یک متد از یک کلاس " +"پایه که متد دیگری را که در همان کلاس پایه تعریف شده فراخوانی می‌کند، ممکن است در نهایت متدی از یک کلاس مشتق‌شده را فراخوانی کند که آن را بازنویسی کرده است. (برای " +"برنامه‌نویسان C++: تمام متدها در پایتون به‌طور مؤثر ``virtual`` هستند.)" #: ../../tutorial/classes.rst:605 msgid "" -"An overriding method in a derived class may in fact want to extend rather " -"than simply replace the base class method of the same name. There is a " -"simple way to call the base class method directly: just call " -"``BaseClassName.methodname(self, arguments)``. This is occasionally useful " -"to clients as well. (Note that this only works if the base class is " -"accessible as ``BaseClassName`` in the global scope.)" +"An overriding method in a derived class may in fact want to extend rather than simply replace the base class method of the same name. There is a simple way to call " +"the base class method directly: just call ``BaseClassName.methodname(self, arguments)``. This is occasionally useful to clients as well. (Note that this only " +"works if the base class is accessible as ``BaseClassName`` in the global scope.)" msgstr "" -"یک متد بازنویسی‌شده در یک کلاس مشتق‌شده ممکن است در واقع بخواهد به جای " -"اینکه صرفاً متد کلاس پایه را با همین نام جایگزین کند، آن را گسترش دهد. یک " -"راه ساده برای فراخوانی مستقیم متد کلاس پایه وجود دارد: فقط " -"``BaseClassName.methodname(self, arguments)`` را فراخوانی کنید. این روش گاهی برای " -"کاربران (clients) نیز مفید است. (توجه داشته باشید که این روش تنها زمانی کار می‌کند که کلاس پایه " -"به عنوان ``BaseClassName`` در محدوده‌ی سراسری (global scope) قابل دسترسی باشد.)" +"یک متد بازنویسی‌شده در یک کلاس مشتق‌شده ممکن است در واقع بخواهد به جای اینکه صرفاً متد کلاس پایه را با همین نام جایگزین کند، آن را گسترش دهد. یک راه ساده برای فراخوانی " +"مستقیم متد کلاس پایه وجود دارد: فقط ``BaseClassName.methodname(self, arguments)`` را فراخوانی کنید. این روش گاهی برای کاربران (clients) نیز مفید است. (توجه داشته " +"باشید که این روش تنها زمانی کار می‌کند که کلاس پایه به عنوان ``BaseClassName`` در محدوده‌ی سراسری (global scope) قابل دسترسی باشد.)" #: ../../tutorial/classes.rst:612 msgid "Python has two built-in functions that work with inheritance:" @@ -1314,37 +1002,27 @@ msgstr "پایتون دو تابع داخلی دارد که با ارث‌بری #: ../../tutorial/classes.rst:614 msgid "" -"Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)`` " -"will be ``True`` only if ``obj.__class__`` is :class:`int` or some class " -"derived from :class:`int`." +"Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)`` will be ``True`` only if ``obj.__class__`` is :class:`int` or some class derived " +"from :class:`int`." msgstr "" -"برای بررسی نوع یک نمونه (instance) از :func:`isinstance` استفاده کنید: ``isinstance(obj, int)`` " -"تنها زمانی ``True`` خواهد بود که ``obj.__class__`` از نوع :class:`int` باشد یا کلاسی " -"که از :class:`int` مشتق شده باشد." +"برای بررسی نوع یک نمونه (instance) از :func:`isinstance` استفاده کنید: ``isinstance(obj, int)`` تنها زمانی ``True`` خواهد بود که ``obj.__class__`` از " +"نوع :class:`int` باشد یا کلاسی که از :class:`int` مشتق شده باشد." #: ../../tutorial/classes.rst:618 msgid "" -"Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)`` " -"is ``True`` since :class:`bool` is a subclass of :class:`int`. However, " -"``issubclass(float, int)`` is ``False`` since :class:`float` is not a " -"subclass of :class:`int`." +"Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)`` is ``True`` since :class:`bool` is a subclass of :class:`int`. However, " +"``issubclass(float, int)`` is ``False`` since :class:`float` is not a subclass of :class:`int`." msgstr "" -"برای بررسی ارث‌بری کلاسها از :func:`issubclass` استفاده کنید: ``issubclass(bool, int)`` " -"مقدار ``True`` است چون :class:`bool` زیرکلاسی از :class:`int` است. با این حال، " -"``issubclass(float, int)`` مقدار ``False`` است چون :class:`float` زیرکلاسی از " -":class:`int` نیست." +"برای بررسی ارث‌بری کلاسها از :func:`issubclass` استفاده کنید: ``issubclass(bool, int)`` مقدار ``True`` است چون :class:`bool` زیرکلاسی از :class:`int` است. با این " +"حال، ``issubclass(float, int)`` مقدار ``False`` است چون :class:`float` زیرکلاسی از :class:`int` نیست." #: ../../tutorial/classes.rst:628 msgid "Multiple Inheritance" msgstr "ارث‌بری چندگانه" #: ../../tutorial/classes.rst:630 -msgid "" -"Python supports a form of multiple inheritance as well. A class definition " -"with multiple base classes looks like this::" -msgstr "" -"پایتون همچنین از نوعی ارث‌بری چندگانه پشتیبانی می‌کند. تعریف یک کلاس " -"با چندین کلاس پایه به این شکل است::" +msgid "Python supports a form of multiple inheritance as well. A class definition with multiple base classes looks like this::" +msgstr "پایتون همچنین از نوعی ارث‌بری چندگانه پشتیبانی می‌کند. تعریف یک کلاس با چندین کلاس پایه به این شکل است::" #: ../../tutorial/classes.rst:633 msgid "" @@ -1364,63 +1042,36 @@ msgstr "" #: ../../tutorial/classes.rst:640 msgid "" -"For most purposes, in the simplest cases, you can think of the search for " -"attributes inherited from a parent class as depth-first, left-to-right, not " -"searching twice in the same class where there is an overlap in the " -"hierarchy. Thus, if an attribute is not found in :class:`!DerivedClassName`, " -"it is searched for in :class:`!Base1`, then (recursively) in the base " -"classes of :class:`!Base1`, and if it was not found there, it was searched " -"for in :class:`!Base2`, and so on." -msgstr "" -"برای بیشتر کاربردها، در ساده‌ترین موارد، می‌توانید جستجو برای " -"ویژگیهای به‌ارث‌برده‌شده از یک کلاس والد را به‌صورت عمق‌اول، چپ‌به‌راست، " -"بدون جستجوی دوباره در همان کلاس در جایی که همپوشانی در سلسله‌مراتب وجود دارد، " -"در نظر بگیرید. بنابراین، اگر ویژگی‌ای در :class:`!DerivedClassName` یافت نشد، " -"در :class:`!Base1` جستجو می‌شود، سپس (به‌صورت بازگشتی) در کلاسهای پایه‌ی " -":class:`!Base1`، و اگر در آنجا یافت نشد، در " -":class:`!Base2` جستجو می‌شود، و به همین ترتیب." +"For most purposes, in the simplest cases, you can think of the search for attributes inherited from a parent class as depth-first, left-to-right, not searching " +"twice in the same class where there is an overlap in the hierarchy. Thus, if an attribute is not found in :class:`!DerivedClassName`, it is searched for in :class:`!" +"Base1`, then (recursively) in the base classes of :class:`!Base1`, and if it was not found there, it was searched for in :class:`!Base2`, and so on." +msgstr "" +"برای بیشتر کاربردها، در ساده‌ترین موارد، می‌توانید جستجو برای ویژگیهای به‌ارث‌برده‌شده از یک کلاس والد را به‌صورت عمق‌اول، چپ‌به‌راست، بدون جستجوی دوباره در همان کلاس در " +"جایی که همپوشانی در سلسله‌مراتب وجود دارد، در نظر بگیرید. بنابراین، اگر ویژگی‌ای در :class:`!DerivedClassName` یافت نشد، در :class:`!Base1` جستجو می‌شود، سپس (به‌صورت " +"بازگشتی) در کلاسهای پایه‌ی :class:`!Base1`، و اگر در آنجا یافت نشد، در :class:`!Base2` جستجو می‌شود، و به همین ترتیب." #: ../../tutorial/classes.rst:647 msgid "" -"In fact, it is slightly more complex than that; the method resolution order " -"changes dynamically to support cooperative calls to :func:`super`. This " -"approach is known in some other multiple-inheritance languages as call-next-" -"method and is more powerful than the super call found in single-inheritance " -"languages." +"In fact, it is slightly more complex than that; the method resolution order changes dynamically to support cooperative calls to :func:`super`. This approach is " +"known in some other multiple-inheritance languages as call-next-method and is more powerful than the super call found in single-inheritance languages." msgstr "" -"در واقع، این موضوع کمی پیچیده‌تر از این است؛ ترتیب حل متد " -"به‌صورت پویا تغییر می‌کند تا از فراخوانی‌های مشارکتی به :func:`super` پشتیبانی کند. این " -"رویکرد در برخی دیگر از زبانهای دارای ارث‌بری چندگانه با نام call-next-" -"method شناخته می‌شود و از فراخوانی super موجود در زبانهای دارای ارث‌بری تکی " -"قدرتمندتر است." +"در واقع، این موضوع کمی پیچیده‌تر از این است؛ ترتیب حل متد به‌صورت پویا تغییر می‌کند تا از فراخوانی‌های مشارکتی به :func:`super` پشتیبانی کند. این رویکرد در برخی دیگر " +"از زبانهای دارای ارث‌بری چندگانه با نام call-next-method شناخته می‌شود و از فراخوانی super موجود در زبانهای دارای ارث‌بری تکی قدرتمندتر است." #: ../../tutorial/classes.rst:653 msgid "" -"Dynamic ordering is necessary because all cases of multiple inheritance " -"exhibit one or more diamond relationships (where at least one of the parent " -"classes can be accessed through multiple paths from the bottommost class). " -"For example, all classes inherit from :class:`object`, so any case of " -"multiple inheritance provides more than one path to reach :class:`object`. " -"To keep the base classes from being accessed more than once, the dynamic " -"algorithm linearizes the search order in a way that preserves the left-to-" -"right ordering specified in each class, that calls each parent only once, " -"and that is monotonic (meaning that a class can be subclassed without " -"affecting the precedence order of its parents). Taken together, these " -"properties make it possible to design reliable and extensible classes with " +"Dynamic ordering is necessary because all cases of multiple inheritance exhibit one or more diamond relationships (where at least one of the parent classes can be " +"accessed through multiple paths from the bottommost class). For example, all classes inherit from :class:`object`, so any case of multiple inheritance provides " +"more than one path to reach :class:`object`. To keep the base classes from being accessed more than once, the dynamic algorithm linearizes the search order in a " +"way that preserves the left-to-right ordering specified in each class, that calls each parent only once, and that is monotonic (meaning that a class can be " +"subclassed without affecting the precedence order of its parents). Taken together, these properties make it possible to design reliable and extensible classes with " "multiple inheritance. For more detail, see :ref:`python_2.3_mro`." msgstr "" -"ترتیب‌دهی پویا ضروری است زیرا همه‌ی موارد ارث‌بری چندگانه " -"دارای یک یا چند رابطه‌ی الماسی هستند (جایی که حداقل یکی از کلاسهای " -"والد از طریق چندین مسیر از پایین‌ترین کلاس قابل دسترسی است). " -"برای مثال، همه‌ی کلاسها از :class:`object` ارث‌بری می‌کنند، بنابراین هر موردی از " -"ارث‌بری چندگانه بیش از یک مسیر برای رسیدن به :class:`object` فراهم می‌کند. " -"برای جلوگیری از دسترسی بیش از یک بار به کلاسهای پایه، الگوریتم پویا " -"ترتیب جستجو را به‌گونه‌ای خطی‌سازی می‌کند که ترتیب چپ‌به‌راست " -"مشخص‌شده در هر کلاس را حفظ کند، که هر والد را فقط یک بار فراخوانی می‌کند، " -"و یکنواخت است (به این معنی که یک کلاس می‌تواند زیرکلاس‌ داشته باشد بدون " -"اینکه بر ترتیب اولویت والدین آن تأثیر بگذارد). این ویژگیها در کنار هم، " -"طراحی کلاسهای قابل اعتماد و قابل توسعه با " -"ارث‌بری چندگانه را ممکن می‌سازند. برای جزئیات بیشتر، به :ref:`python_2.3_mro` مراجعه کنید." +"ترتیب‌دهی پویا ضروری است زیرا همه‌ی موارد ارث‌بری چندگانه دارای یک یا چند رابطه‌ی الماسی هستند (جایی که حداقل یکی از کلاسهای والد از طریق چندین مسیر از پایین‌ترین کلاس " +"قابل دسترسی است). برای مثال، همه‌ی کلاسها از :class:`object` ارث‌بری می‌کنند، بنابراین هر موردی از ارث‌بری چندگانه بیش از یک مسیر برای رسیدن به :class:`object` فراهم " +"می‌کند. برای جلوگیری از دسترسی بیش از یک بار به کلاسهای پایه، الگوریتم پویا ترتیب جستجو را به‌گونه‌ای خطی‌سازی می‌کند که ترتیب چپ‌به‌راست مشخص‌شده در هر کلاس را حفظ کند، " +"که هر والد را فقط یک بار فراخوانی می‌کند، و یکنواخت است (به این معنی که یک کلاس می‌تواند زیرکلاس‌ داشته باشد بدون اینکه بر ترتیب اولویت والدین آن تأثیر بگذارد). این " +"ویژگیها در کنار هم، طراحی کلاسهای قابل اعتماد و قابل توسعه با ارث‌بری چندگانه را ممکن می‌سازند. برای جزئیات بیشتر، به :ref:`python_2.3_mro` مراجعه کنید." #: ../../tutorial/classes.rst:670 msgid "Private Variables" @@ -1428,55 +1079,33 @@ msgstr "متغیر‌های خصوصی" #: ../../tutorial/classes.rst:672 msgid "" -"\"Private\" instance variables that cannot be accessed except from inside an " -"object don't exist in Python. However, there is a convention that is " -"followed by most Python code: a name prefixed with an underscore (e.g. " -"``_spam``) should be treated as a non-public part of the API (whether it is " -"a function, a method or a data member). It should be considered an " -"implementation detail and subject to change without notice." -msgstr "" -"متغیرهای نمونه‌ای «خصوصی» که جز از درون یک " -"شیء قابل دسترسی نیستند، در پایتون وجود ندارند. با این حال، یک قرارداد وجود دارد که " -"توسط بیشتر کدهای پایتون دنبال می‌شود: یک نام که با زیرخط آغاز می‌شود (مثلاً " -"``_spam``) باید به عنوان بخشی غیرعمومی از API در نظر گرفته شود (خواه " -"یک تابع، یک متد یا یک عضو داده باشد). باید به عنوان یک " +"\"Private\" instance variables that cannot be accessed except from inside an object don't exist in Python. However, there is a convention that is followed by most " +"Python code: a name prefixed with an underscore (e.g. ``_spam``) should be treated as a non-public part of the API (whether it is a function, a method or a data " +"member). It should be considered an implementation detail and subject to change without notice." +msgstr "" +"متغیرهای نمونه‌ای «خصوصی» که جز از درون یک شیء قابل دسترسی نیستند، در پایتون وجود ندارند. با این حال، یک قرارداد وجود دارد که توسط بیشتر کدهای پایتون دنبال می‌شود: " +"یک نام که با زیرخط آغاز می‌شود (مثلاً ``_spam``) باید به عنوان بخشی غیرعمومی از API در نظر گرفته شود (خواه یک تابع، یک متد یا یک عضو داده باشد). باید به عنوان یک " "جزئیات پیاده‌سازی در نظر گرفته شود و ممکن است بدون اطلاع‌رسانی تغییر کند." #: ../../tutorial/classes.rst:682 msgid "" -"Since there is a valid use-case for class-private members (namely to avoid " -"name clashes of names with names defined by subclasses), there is limited " -"support for such a mechanism, called :dfn:`name mangling`. Any identifier " -"of the form ``__spam`` (at least two leading underscores, at most one " -"trailing underscore) is textually replaced with ``_classname__spam``, where " -"``classname`` is the current class name with leading underscore(s) " -"stripped. This mangling is done without regard to the syntactic position of " -"the identifier, as long as it occurs within the definition of a class." -msgstr "" -"از آنجا که یک مورد استفاده‌ی معتبر برای اعضای خصوصی کلاس وجود دارد (به‌ویژه برای جلوگیری از " -"برخورد نام‌ها با نام‌های تعریف‌شده توسط زیرکلاسها)، پشتیبانی محدودی " -"برای چنین مکانیزمی، به نام :dfn:`name mangling` (دستکاری نام) وجود دارد. هر شناسه‌ای " -"به شکل ``__spam`` (حداقل دو زیرخط در ابتدا، حداکثر یک " -"زیرخط در انتها) به‌صورت متنی با ``_classname__spam`` جایگزین می‌شود، که در آن " -"``classname`` نام کلاس جاری است با زیرخط‌های ابتدایی " -"حذف‌شده. این دستکاری بدون در نظر گرفتن جایگاه نحوی " -"شناسه انجام می‌شود، تا زمانی که درون تعریف یک کلاس رخ دهد." +"Since there is a valid use-case for class-private members (namely to avoid name clashes of names with names defined by subclasses), there is limited support for " +"such a mechanism, called :dfn:`name mangling`. Any identifier of the form ``__spam`` (at least two leading underscores, at most one trailing underscore) is " +"textually replaced with ``_classname__spam``, where ``classname`` is the current class name with leading underscore(s) stripped. This mangling is done without " +"regard to the syntactic position of the identifier, as long as it occurs within the definition of a class." +msgstr "" +"از آنجا که یک مورد استفاده‌ی معتبر برای اعضای خصوصی کلاس وجود دارد (به‌ویژه برای جلوگیری از برخورد نام‌ها با نام‌های تعریف‌شده توسط زیرکلاسها)، پشتیبانی محدودی برای چنین " +"مکانیزمی، به نام :dfn:`name mangling` (دستکاری نام) وجود دارد. هر شناسه‌ای به شکل ``__spam`` (حداقل دو زیرخط در ابتدا، حداکثر یک زیرخط در انتها) به‌صورت متنی با " +"``_classname__spam`` جایگزین می‌شود، که در آن ``classname`` نام کلاس جاری است با زیرخط‌های ابتدایی حذف‌شده. این دستکاری بدون در نظر گرفتن جایگاه نحوی شناسه انجام " +"می‌شود، تا زمانی که درون تعریف یک کلاس رخ دهد." #: ../../tutorial/classes.rst:693 -msgid "" -"The :ref:`private name mangling specifications ` for " -"details and special cases." -msgstr "" -"برای جزئیات و موارد خاص، به :ref:`مشخصات دستکاری نام‌های خصوصی ` " -"مراجعه کنید." +msgid "The :ref:`private name mangling specifications ` for details and special cases." +msgstr "برای جزئیات و موارد خاص، به :ref:`مشخصات دستکاری نام‌های خصوصی ` مراجعه کنید." #: ../../tutorial/classes.rst:696 -msgid "" -"Name mangling is helpful for letting subclasses override methods without " -"breaking intraclass method calls. For example::" -msgstr "" -"دستکاری نام برای این مفید است که به زیرکلاسها اجازه دهد متدها را بدون " -"شکستن فراخوانی‌های متد درون‌کلاسی بازنویسی کنند. برای مثال::" +msgid "Name mangling is helpful for letting subclasses override methods without breaking intraclass method calls. For example::" +msgstr "دستکاری نام برای این مفید است که به زیرکلاسها اجازه دهد متدها را بدون شکستن فراخوانی‌های متد درون‌کلاسی بازنویسی کنند. برای مثال::" #: ../../tutorial/classes.rst:699 msgid "" @@ -1520,43 +1149,29 @@ msgstr "" #: ../../tutorial/classes.rst:718 msgid "" -"The above example would work even if ``MappingSubclass`` were to introduce a " -"``__update`` identifier since it is replaced with ``_Mapping__update`` in " -"the ``Mapping`` class and ``_MappingSubclass__update`` in the " -"``MappingSubclass`` class respectively." +"The above example would work even if ``MappingSubclass`` were to introduce a ``__update`` identifier since it is replaced with ``_Mapping__update`` in the " +"``Mapping`` class and ``_MappingSubclass__update`` in the ``MappingSubclass`` class respectively." msgstr "" -"مثال بالا حتی اگر ``MappingSubclass`` یک شناسه‌ی " -"``__update`` معرفی کند، کار خواهد کرد زیرا این شناسه به ترتیب در کلاس " -"``Mapping`` با ``_Mapping__update`` و در کلاس " +"مثال بالا حتی اگر ``MappingSubclass`` یک شناسه‌ی ``__update`` معرفی کند، کار خواهد کرد زیرا این شناسه به ترتیب در کلاس ``Mapping`` با ``_Mapping__update`` و در کلاس " "``MappingSubclass`` با ``_MappingSubclass__update`` جایگزین می‌شود." #: ../../tutorial/classes.rst:723 msgid "" -"Note that the mangling rules are designed mostly to avoid accidents; it " -"still is possible to access or modify a variable that is considered " -"private. This can even be useful in special circumstances, such as in the " -"debugger." +"Note that the mangling rules are designed mostly to avoid accidents; it still is possible to access or modify a variable that is considered private. This can even " +"be useful in special circumstances, such as in the debugger." msgstr "" -"توجه داشته باشید که قوانین دستکاری نام بیشتر برای جلوگیری از اشتباهات طراحی شده‌اند؛ همچنان " -"دسترسی یا تغییر یک متغیر که خصوصی در نظر گرفته می‌شود، " -"ممکن است. این حتی می‌تواند در شرایط خاص، مانند " -"اشکال‌زدایی، مفید باشد." +"توجه داشته باشید که قوانین دستکاری نام بیشتر برای جلوگیری از اشتباهات طراحی شده‌اند؛ همچنان دسترسی یا تغییر یک متغیر که خصوصی در نظر گرفته می‌شود، ممکن است. این حتی " +"می‌تواند در شرایط خاص، مانند اشکال‌زدایی، مفید باشد." #: ../../tutorial/classes.rst:727 msgid "" -"Notice that code passed to ``exec()`` or ``eval()`` does not consider the " -"classname of the invoking class to be the current class; this is similar to " -"the effect of the ``global`` statement, the effect of which is likewise " -"restricted to code that is byte-compiled together. The same restriction " -"applies to ``getattr()``, ``setattr()`` and ``delattr()``, as well as when " -"referencing ``__dict__`` directly." +"Notice that code passed to ``exec()`` or ``eval()`` does not consider the classname of the invoking class to be the current class; this is similar to the effect of " +"the ``global`` statement, the effect of which is likewise restricted to code that is byte-compiled together. The same restriction applies to ``getattr()``, " +"``setattr()`` and ``delattr()``, as well as when referencing ``__dict__`` directly." msgstr "" -"توجه داشته باشید که کد ارسال‌شده به ``exec()`` یا ``eval()`` نام کلاس " -"کلاس فراخوان‌کننده را به عنوان کلاس جاری در نظر نمی‌گیرد؛ این مشابه " -"تأثیر دستور ``global`` است که تأثیر آن نیز به همین ترتیب " -"به کدی که با هم بایت‌کامپایل می‌شوند، محدود است. همین محدودیت " -"برای ``getattr()``، ``setattr()`` و ``delattr()`` نیز اعمال می‌شود، همچنین زمانی که " -"به طور مستقیم به ``__dict__`` ارجاع داده می‌شود." +"توجه داشته باشید که کد ارسال‌شده به ``exec()`` یا ``eval()`` نام کلاس کلاس فراخوان‌کننده را به عنوان کلاس جاری در نظر نمی‌گیرد؛ این مشابه تأثیر دستور ``global`` است که " +"تأثیر آن نیز به همین ترتیب به کدی که با هم بایت‌کامپایل می‌شوند، محدود است. همین محدودیت برای ``getattr()``، ``setattr()`` و ``delattr()`` نیز اعمال می‌شود، همچنین " +"زمانی که به طور مستقیم به ``__dict__`` ارجاع داده می‌شود." #: ../../tutorial/classes.rst:738 msgid "Odds and Ends" @@ -1564,13 +1179,11 @@ msgstr "نکات متفرقه" #: ../../tutorial/classes.rst:740 msgid "" -"Sometimes it is useful to have a data type similar to the Pascal \"record\" " -"or C \"struct\", bundling together a few named data items. The idiomatic " -"approach is to use :mod:`dataclasses` for this purpose::" +"Sometimes it is useful to have a data type similar to the Pascal \"record\" or C \"struct\", bundling together a few named data items. The idiomatic approach is to " +"use :mod:`dataclasses` for this purpose::" msgstr "" -"گاهی اوقات داشتن یک نوع داده مشابه «رکورد» در پاسکال یا " -"«ساختار» در C مفید است، که چندین آیتم داده‌ی نام‌دار را کنار هم بسته‌بندی می‌کند. روش استاندارد " -"برای این کار استفاده از :mod:`dataclasses` است::" +"گاهی اوقات داشتن یک نوع داده مشابه «رکورد» در پاسکال یا «ساختار» در C مفید است، که چندین آیتم داده‌ی نام‌دار را کنار هم بسته‌بندی می‌کند. روش استاندارد برای این کار " +"استفاده از :mod:`dataclasses` است::" #: ../../tutorial/classes.rst:744 msgid "" @@ -1606,43 +1219,29 @@ msgstr "" #: ../../tutorial/classes.rst:760 msgid "" -"A piece of Python code that expects a particular abstract data type can " -"often be passed a class that emulates the methods of that data type " -"instead. For instance, if you have a function that formats some data from a " -"file object, you can define a class with methods :meth:`~io.TextIOBase.read` " -"and :meth:`~io.TextIOBase.readline` that get the data from a string buffer " -"instead, and pass it as an argument." +"A piece of Python code that expects a particular abstract data type can often be passed a class that emulates the methods of that data type instead. For instance, " +"if you have a function that formats some data from a file object, you can define a class with methods :meth:`~io.TextIOBase.read` " +"and :meth:`~io.TextIOBase.readline` that get the data from a string buffer instead, and pass it as an argument." msgstr "" -"یک قطعه کد پایتون که انتظار یک نوع دادهٔ انتزاعی خاص را دارد، اغلب " -"می‌تواند به جای آن، یک کلاس دریافت کند که متدهای آن نوع داده را شبیه‌سازی می‌کند. " -"برای مثال، اگر تابعی دارید که داده‌هایی را از یک شیء فایل قالب‌بندی می‌کند، " -"می‌توانید کلاسی تعریف کنید با متدهای :meth:`~io.TextIOBase.read` " -"و :meth:`~io.TextIOBase.readline` که داده‌ها را از یک بافر رشته‌ای دریافت می‌کنند، " -"و آن را به عنوان آرگومان به تابع ارسال کنید." +"یک قطعه کد پایتون که انتظار یک نوع دادهٔ انتزاعی خاص را دارد، اغلب می‌تواند به جای آن، یک کلاس دریافت کند که متدهای آن نوع داده را شبیه‌سازی می‌کند. برای مثال، اگر " +"تابعی دارید که داده‌هایی را از یک شیء فایل قالب‌بندی می‌کند، می‌توانید کلاسی تعریف کنید با متدهای :meth:`~io.TextIOBase.read` و :meth:`~io.TextIOBase.readline` که " +"داده‌ها را از یک بافر رشته‌ای دریافت می‌کنند، و آن را به عنوان آرگومان به تابع ارسال کنید." #: ../../tutorial/classes.rst:772 msgid "" -":ref:`Instance method objects ` have attributes, " -"too: :attr:`m.__self__ ` is the instance object with the " -"method :meth:`!m`, and :attr:`m.__func__ ` is " -"the :ref:`function object ` corresponding to the method." +":ref:`Instance method objects ` have attributes, too: :attr:`m.__self__ ` is the instance object with the method :meth:`!m`, " +"and :attr:`m.__func__ ` is the :ref:`function object ` corresponding to the method." msgstr "" -":ref:`اشیاء متد نمونه ` نیز ویژگیهایی دارند: " -":attr:`m.__self__ ` شیء نمونه‌ای است که متد :meth:`!m` " -"به آن تعلق دارد، و :attr:`m.__func__ ` همان " -":ref:`شیء تابع ` متناظر با آن متد است." +":ref:`اشیاء متد نمونه ` نیز ویژگیهایی دارند: :attr:`m.__self__ ` شیء نمونه‌ای است که متد :meth:`!m` به آن تعلق دارد، " +"و :attr:`m.__func__ ` همان :ref:`شیء تابع ` متناظر با آن متد است." #: ../../tutorial/classes.rst:782 msgid "Iterators" msgstr "تکرارگرها" #: ../../tutorial/classes.rst:784 -msgid "" -"By now you have probably noticed that most container objects can be looped " -"over using a :keyword:`for` statement::" -msgstr "" -"تا اینجا احتمالاً متوجه شده‌اید که می‌توان روی بیشتر اشیاء ظرف با استفاده از " -"دستور :keyword:`for` حلقه زد::" +msgid "By now you have probably noticed that most container objects can be looped over using a :keyword:`for` statement::" +msgstr "تا اینجا احتمالاً متوجه شده‌اید که می‌توان روی بیشتر اشیاء ظرف با استفاده از دستور :keyword:`for` حلقه زد::" #: ../../tutorial/classes.rst:787 msgid "" @@ -1670,25 +1269,15 @@ msgstr "" #: ../../tutorial/classes.rst:798 msgid "" -"This style of access is clear, concise, and convenient. The use of " -"iterators pervades and unifies Python. Behind the scenes, " -"the :keyword:`for` statement calls :func:`iter` on the container object. " -"The function returns an iterator object that defines the " -"method :meth:`~iterator.__next__` which accesses elements in the container " -"one at a time. When there are no more elements, :meth:`~iterator.__next__` " -"raises a :exc:`StopIteration` exception which tells the :keyword:`!for` loop " -"to terminate. You can call the :meth:`~iterator.__next__` method using " -"the :func:`next` built-in function; this example shows how it all works::" -msgstr "" -"این سبک دسترسی واضح، مختصر و راحت است. استفاده از " -"تکرارگرها در همه‌جا نفوذ کرده و پایتون را یکپارچه می‌کنند. در پشت صحنه، " -"دستور :keyword:`for` تابع :func:`iter` را روی شیء ظرف فراخوانی می‌کند. " -"این تابع یک شیء تکرارگر برمی‌گرداند که " -"متد :meth:`~iterator.__next__` را تعریف می‌کند که به المان‌ها در ظرف " -"یکی یکی دسترسی پیدا می‌کند. وقتی المان‌ها تمام شوند، :meth:`~iterator.__next__` " -"یک استثنای :exc:`StopIteration` ایجاد می‌کند که به حلقه‌ی :keyword:`!for` می‌گوید " -"پایان یابد. می‌توانید متد :meth:`~iterator.__next__` را با استفاده از " -"تابع داخلی :func:`next` فراخوانی کنید؛ این مثال نشان می‌دهد که چگونه همه‌چیز کار می‌کند::" +"This style of access is clear, concise, and convenient. The use of iterators pervades and unifies Python. Behind the scenes, the :keyword:`for` statement " +"calls :func:`iter` on the container object. The function returns an iterator object that defines the method :meth:`~iterator.__next__` which accesses elements in " +"the container one at a time. When there are no more elements, :meth:`~iterator.__next__` raises a :exc:`StopIteration` exception which tells the :keyword:`!for` " +"loop to terminate. You can call the :meth:`~iterator.__next__` method using the :func:`next` built-in function; this example shows how it all works::" +msgstr "" +"این سبک دسترسی واضح، مختصر و راحت است. استفاده از تکرارگرها در همه‌جا نفوذ کرده و پایتون را یکپارچه می‌کنند. در پشت صحنه، دستور :keyword:`for` تابع :func:`iter` را " +"روی شیء ظرف فراخوانی می‌کند. این تابع یک شیء تکرارگر برمی‌گرداند که متد :meth:`~iterator.__next__` را تعریف می‌کند که به المان‌ها در ظرف یکی یکی دسترسی پیدا می‌کند. " +"وقتی المان‌ها تمام شوند، :meth:`~iterator.__next__` یک استثنای :exc:`StopIteration` ایجاد می‌کند که به حلقه‌ی :keyword:`!for` می‌گوید پایان یابد. می‌توانید " +"متد :meth:`~iterator.__next__` را با استفاده از تابع داخلی :func:`next` فراخوانی کنید؛ این مثال نشان می‌دهد که چگونه همه‌چیز کار می‌کند::" #: ../../tutorial/classes.rst:807 msgid "" @@ -1726,17 +1315,11 @@ msgstr "" #: ../../tutorial/classes.rst:823 msgid "" -"Having seen the mechanics behind the iterator protocol, it is easy to add " -"iterator behavior to your classes. Define an :meth:`~container.__iter__` " -"method which returns an object with a :meth:`~iterator.__next__` method. If " -"the class defines :meth:`!__next__`, then :meth:`!__iter__` can just return " -"``self``::" +"Having seen the mechanics behind the iterator protocol, it is easy to add iterator behavior to your classes. Define an :meth:`~container.__iter__` method which " +"returns an object with a :meth:`~iterator.__next__` method. If the class defines :meth:`!__next__`, then :meth:`!__iter__` can just return ``self``::" msgstr "" -"حالا که با سازوکار پشت پروتکل تکرارگر آشنا شدید، اضافه کردن " -"رفتار تکرارگر به کلاسهایتان آسان است. یک متد :meth:`~container.__iter__` تعریف کنید " -"که یک شیء با متد :meth:`~iterator.__next__` برمی‌گرداند. اگر " -"کلاس :meth:`!__next__` را تعریف کرده باشد، آنگاه :meth:`!__iter__` می‌تواند فقط " -"``self`` را برگرداند::" +"حالا که با سازوکار پشت پروتکل تکرارگر آشنا شدید، اضافه کردن رفتار تکرارگر به کلاسهایتان آسان است. یک متد :meth:`~container.__iter__` تعریف کنید که یک شیء با " +"متد :meth:`~iterator.__next__` برمی‌گرداند. اگر کلاس :meth:`!__next__` را تعریف کرده باشد، آنگاه :meth:`!__iter__` می‌تواند فقط ``self`` را برگرداند::" #: ../../tutorial/classes.rst:828 msgid "" @@ -1800,20 +1383,13 @@ msgstr "تولیدکننده‌ها" #: ../../tutorial/classes.rst:862 msgid "" -":term:`Generators ` are a simple and powerful tool for creating " -"iterators. They are written like regular functions but use " -"the :keyword:`yield` statement whenever they want to return data. Each " -"time :func:`next` is called on it, the generator resumes where it left off " -"(it remembers all the data values and which statement was last executed). " -"An example shows that generators can be trivially easy to create::" -msgstr "" -":term:`Generators ` یک ابزار ساده و قدرتمند برای ایجاد " -"اینتراتور‌ها هستند. آن‌ها مانند توابع عادی نوشته می‌شوند اما هر زمان که می‌خواهند " -"داده‌ای را بازگردانند از دستور :keyword:`yield` استفاده می‌کنند. هر " -"بار که :func:`next` بر روی آن فراخوانی می‌شود، مولد از جایی که متوقف شده " -"ادامه می‌یابد (تمام مقادیر داده‌ها و اینکه آخرین دستور اجرا شده چه بوده را " -"به خاطر می‌آورد). یک مثال نشان می‌دهد که ایجاد مولد‌ها می‌تواند به طرز " -"باور‌نکردنی ساده باشد::" +":term:`Generators ` are a simple and powerful tool for creating iterators. They are written like regular functions but use the :keyword:`yield` " +"statement whenever they want to return data. Each time :func:`next` is called on it, the generator resumes where it left off (it remembers all the data values and " +"which statement was last executed). An example shows that generators can be trivially easy to create::" +msgstr "" +":term:`Generators ` یک ابزار ساده و قدرتمند برای ایجاد اینتراتور‌ها هستند. آن‌ها مانند توابع عادی نوشته می‌شوند اما هر زمان که می‌خواهند داده‌ای را بازگردانند " +"از دستور :keyword:`yield` استفاده می‌کنند. هر بار که :func:`next` بر روی آن فراخوانی می‌شود، مولد از جایی که متوقف شده ادامه می‌یابد (تمام مقادیر داده‌ها و اینکه آخرین " +"دستور اجرا شده چه بوده را به خاطر می‌آورد). یک مثال نشان می‌دهد که ایجاد مولد‌ها می‌تواند به طرز باور‌نکردنی ساده باشد::" #: ../../tutorial/classes.rst:869 msgid "" @@ -1845,40 +1421,27 @@ msgstr "" #: ../../tutorial/classes.rst:883 msgid "" -"Anything that can be done with generators can also be done with class-based " -"iterators as described in the previous section. What makes generators so " -"compact is that the :meth:`~iterator.__iter__` " -"and :meth:`~generator.__next__` methods are created automatically." +"Anything that can be done with generators can also be done with class-based iterators as described in the previous section. What makes generators so compact is " +"that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods are created automatically." msgstr "" -"هر چیزی که با تولیدکننده‌ها قابل انجام است، می‌تواند با استفاده " -"از تکرارگرهای مبتنی بر کلاس نیز انجام شود، همانطور که در بخش قبلی توضیح داده " -"شد. آنچه تولیدکننده‌ها را فشرده می‌کند، این است که روش‌های " -":meth:`~iterator.__iter__` و :meth:`~generator.__next__` به‌طور خودکار " -"ایجاد می‌شوند." +"هر چیزی که با تولیدکننده‌ها قابل انجام است، می‌تواند با استفاده از تکرارگرهای مبتنی بر کلاس نیز انجام شود، همانطور که در بخش قبلی توضیح داده شد. آنچه تولیدکننده‌ها را " +"فشرده می‌کند، این است که روش‌های :meth:`~iterator.__iter__` و :meth:`~generator.__next__` به‌طور خودکار ایجاد می‌شوند." #: ../../tutorial/classes.rst:888 msgid "" -"Another key feature is that the local variables and execution state are " -"automatically saved between calls. This made the function easier to write " -"and much more clear than an approach using instance variables like " -"``self.index`` and ``self.data``." +"Another key feature is that the local variables and execution state are automatically saved between calls. This made the function easier to write and much more " +"clear than an approach using instance variables like ``self.index`` and ``self.data``." msgstr "" -"یکی دیگر از ویژگیهای کلیدی این است که متغیر‌های محلی و وضعیت اجرا به‌طور " -"خودکار بین فراخوانی‌ها ذخیره می‌شوند. این امر نوشتن تابع را آسان‌تر و خیلی " -"واضح‌تر از رویکردی که از متغیر‌های نمونه‌ای مانند ``self.index`` و " -"``self.data`` استفاده می‌کند، کرده است." +"یکی دیگر از ویژگیهای کلیدی این است که متغیر‌های محلی و وضعیت اجرا به‌طور خودکار بین فراخوانی‌ها ذخیره می‌شوند. این امر نوشتن تابع را آسان‌تر و خیلی واضح‌تر از رویکردی که " +"از متغیر‌های نمونه‌ای مانند ``self.index`` و ``self.data`` استفاده می‌کند، کرده است." #: ../../tutorial/classes.rst:893 msgid "" -"In addition to automatic method creation and saving program state, when " -"generators terminate, they automatically raise :exc:`StopIteration`. In " -"combination, these features make it easy to create iterators with no more " -"effort than writing a regular function." +"In addition to automatic method creation and saving program state, when generators terminate, they automatically raise :exc:`StopIteration`. In combination, these " +"features make it easy to create iterators with no more effort than writing a regular function." msgstr "" -"علاوه بر ایجاد خودکار متد‌ها و ذخیره سازی وضعیت برنامه، زمانی که تولیدکننده‌ها " -"خاتمه می‌یابند، به‌طور خودکار :exc:`StopIteration` را ایجاد می‌کنند. این " -"ویژگیها به صورت ترکیبی، ساختن تکرارگرها را به همان سادگی نوشتن یک تابع عادی " -"امکان پذیر می‌سازند." +"علاوه بر ایجاد خودکار متد‌ها و ذخیره سازی وضعیت برنامه، زمانی که تولیدکننده‌ها خاتمه می‌یابند، به‌طور خودکار :exc:`StopIteration` را ایجاد می‌کنند. این ویژگیها به صورت " +"ترکیبی، ساختن تکرارگرها را به همان سادگی نوشتن یک تابع عادی امکان پذیر می‌سازند." #: ../../tutorial/classes.rst:902 msgid "Generator Expressions" @@ -1886,23 +1449,17 @@ msgstr "عبارات تولیدکننده" #: ../../tutorial/classes.rst:904 msgid "" -"Some simple generators can be coded succinctly as expressions using a syntax " -"similar to list comprehensions but with parentheses instead of square " -"brackets. These expressions are designed for situations where the generator " -"is used right away by an enclosing function. Generator expressions are more " -"compact but less versatile than full generator definitions and tend to be " -"more memory friendly than equivalent list comprehensions." +"Some simple generators can be coded succinctly as expressions using a syntax similar to list comprehensions but with parentheses instead of square brackets. These " +"expressions are designed for situations where the generator is used right away by an enclosing function. Generator expressions are more compact but less versatile " +"than full generator definitions and tend to be more memory friendly than equivalent list comprehensions." msgstr "" -"برخی از تولیدکننده‌های ساده را می‌توان به‌صورت مختصر به عنوان عبارت کدنویسی کرد، با استفاده از یک نحو " -"مشابه درک‌لیستها اما با پرانتز به جای کروشه‌ی " -"باز. این عبارت‌ها برای شرایطی طراحی شده‌اند که تولیدکننده " -"بلافاصله توسط یک تابع محاط‌شونده استفاده می‌شود. عبارت‌های تولیدکننده فشرده‌تر " -"هستند اما نسبت به تعاریف کامل تولیدکننده، انعطاف‌پذیری کمتری دارند و معمولاً " -"نسبت به درک‌لیستهای معادل، با حافظه سازگارتر هستند." +"برخی از تولیدکننده‌های ساده را می‌توان به‌صورت مختصر به عنوان عبارت کدنویسی کرد، با استفاده از یک نحو مشابه درک‌لیستها اما با پرانتز به جای کروشه‌ی باز. این عبارت‌ها برای " +"شرایطی طراحی شده‌اند که تولیدکننده بلافاصله توسط یک تابع محاط‌شونده استفاده می‌شود. عبارت‌های تولیدکننده فشرده‌تر هستند اما نسبت به تعاریف کامل تولیدکننده، انعطاف‌پذیری " +"کمتری دارند و معمولاً نسبت به درک‌لیستهای معادل، با حافظه سازگارتر هستند." #: ../../tutorial/classes.rst:911 msgid "Examples::" -msgstr "مثالها" +msgstr "مثالها::" #: ../../tutorial/classes.rst:913 msgid "" @@ -1916,8 +1473,7 @@ msgid "" "\n" ">>> unique_words = set(word for line in page for word in line.split())\n" "\n" -">>> valedictorian = max((student.gpa, student.name) for student in " -"graduates)\n" +">>> valedictorian = max((student.gpa, student.name) for student in graduates)\n" "\n" ">>> data = 'golf'\n" ">>> list(data[i] for i in range(len(data)-1, -1, -1))\n" @@ -1933,8 +1489,7 @@ msgstr "" "\n" ">>> unique_words = set(word for line in page for word in line.split())\n" "\n" -">>> valedictorian = max((student.gpa, student.name) for student in " -"graduates)\n" +">>> valedictorian = max((student.gpa, student.name) for student in graduates)\n" "\n" ">>> data = 'golf'\n" ">>> list(data[i] for i in range(len(data)-1, -1, -1))\n" @@ -1946,19 +1501,13 @@ msgstr "پاورقی‌ها" #: ../../tutorial/classes.rst:933 msgid "" -"Except for one thing. Module objects have a secret read-only attribute " -"called :attr:`~object.__dict__` which returns the dictionary used to " -"implement the module's namespace; the name ``__dict__`` is an attribute but " -"not a global name. Obviously, using this violates the abstraction of " -"namespace implementation, and should be restricted to things like post-" -"mortem debuggers." -msgstr "" -"به جز یک مورد. اشیاء ماژول یک ویژگی مخفی فقط‌خواندنی دارند " -"به نام :attr:`~object.__dict__` که دیکشنری مورد استفاده برای " -"پیاده‌سازی فضای نام ماژول را برمی‌گرداند؛ نام ``__dict__`` یک ویژگی است اما " -"یک نام سراسری نیست. بدیهی است که استفاده از این ویژگی، انتزاع " -"پیاده‌سازی فضای نام را نقض می‌کند و باید به مواردی مانند " -"اشکال‌زدای پس‌ازمرگ محدود شود." +"Except for one thing. Module objects have a secret read-only attribute called :attr:`~object.__dict__` which returns the dictionary used to implement the module's " +"namespace; the name ``__dict__`` is an attribute but not a global name. Obviously, using this violates the abstraction of namespace implementation, and should be " +"restricted to things like post-mortem debuggers." +msgstr "" +"به جز یک مورد. اشیاء ماژول یک ویژگی مخفی فقط‌خواندنی دارند به نام :attr:`~object.__dict__` که دیکشنری مورد استفاده برای پیاده‌سازی فضای نام ماژول را برمی‌گرداند؛ نام " +"``__dict__`` یک ویژگی است اما یک نام سراسری نیست. بدیهی است که استفاده از این ویژگی، انتزاع پیاده‌سازی فضای نام را نقض می‌کند و باید به مواردی مانند اشکال‌زدای پس‌ازمرگ " +"محدود شود." #: ../../tutorial/classes.rst:343 msgid "object" diff --git a/tutorial/controlflow.po b/tutorial/controlflow.po index 631e43fe2..fab75846e 100644 --- a/tutorial/controlflow.po +++ b/tutorial/controlflow.po @@ -12,7 +12,7 @@ msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-07-25 12:59+0330\n" -"PO-Revision-Date: 2021-06-28 01:50+0000\n" +"PO-Revision-Date: 2026-08-14 10:15+0330\n" "Last-Translator: Alireza Shabani (Revisto) , 2025\n" "Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/" "fa/)\n" @@ -21,26 +21,29 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Generator: Poedit 3.6\n" #: ../../tutorial/controlflow.rst:5 msgid "More Control Flow Tools" -msgstr "" +msgstr "ابزارهای بیشتر برای کنترل جریان" #: ../../tutorial/controlflow.rst:7 msgid "" "As well as the :keyword:`while` statement just introduced, Python uses a few " "more that we will encounter in this chapter." msgstr "" +"علاوه بر دستور :keyword:`while` که به‌تازگی معرفی شد، پایتون چند مورد دیگر " +"نیز دارد که در این فصل با آن‌ها آشنا خواهیم شد." #: ../../tutorial/controlflow.rst:14 msgid ":keyword:`!if` Statements" -msgstr "" +msgstr "دستورهای :keyword:`!if`" #: ../../tutorial/controlflow.rst:16 msgid "" "Perhaps the most well-known statement type is the :keyword:`if` statement. " "For example::" -msgstr "" +msgstr "شاید شناخته‌شده‌ترین نوع دستور، دستور :keyword:`if` باشد. برای مثال::" #: ../../tutorial/controlflow.rst:19 msgid "" @@ -58,6 +61,19 @@ msgid "" "...\n" "More" msgstr "" +">>> x = int(input(\"Please enter an integer: \"))\n" +"Please enter an integer: 42\n" +">>> if x < 0:\n" +"... x = 0\n" +"... print('Negative changed to zero')\n" +"... elif x == 0:\n" +"... print('Zero')\n" +"... elif x == 1:\n" +"... print('Single')\n" +"... else:\n" +"... print('More')\n" +"...\n" +"More" #: ../../tutorial/controlflow.rst:33 msgid "" @@ -67,6 +83,11 @@ msgid "" "if` ... :keyword:`!elif` ... :keyword:`!elif` ... sequence is a substitute " "for the ``switch`` or ``case`` statements found in other languages." msgstr "" +"می‌تواند صفر یا چند بخش :keyword:`elif` وجود داشته باشد و بخش :keyword:`else` " +"اختیاری است. کلمهٔ کلیدی ':keyword:`!elif`' کوتاه‌شدهٔ 'else if' است و برای " +"جلوگیری از تورفتگی بیش از حد مفید است. یک دنبالهٔ :keyword:`!" +"if` ... :keyword:`!elif` ... :keyword:`!elif` ... جایگزینی برای دستورهای " +"``switch`` یا ``case`` موجود در زبان‌های دیگر است." #: ../../tutorial/controlflow.rst:39 msgid "" @@ -74,10 +95,13 @@ msgid "" "specific types or attributes, you may also find the :keyword:`!match` " "statement useful. For more details see :ref:`tut-match`." msgstr "" +"اگر یک مقدار یکسان را با چندین مقدار ثابت مقایسه می‌کنید، یا نوع‌ها یا " +"ویژگی‌های خاصی را بررسی می‌کنید، ممکن است دستور :keyword:`!match` نیز برایتان " +"مفید باشد. برای جزئیات بیشتر به :ref:`tut-match` مراجعه کنید." #: ../../tutorial/controlflow.rst:46 msgid ":keyword:`!for` Statements" -msgstr "" +msgstr "دستورهای :keyword:`!for`" #: ../../tutorial/controlflow.rst:51 msgid "" @@ -89,6 +113,12 @@ msgid "" "(a list or a string), in the order that they appear in the sequence. For " "example (no pun intended):" msgstr "" +"دستور :keyword:`for` در پایتون کمی با چیزی که ممکن است در C یا Pascal به آن " +"عادت کرده باشید تفاوت دارد. به‌جای اینکه همیشه روی یک تصاعد حسابی از اعداد " +"پیمایش کند (مانند Pascal)، یا به کاربر امکان تعریف هم گام پیمایش و هم شرط " +"توقف را بدهد (مانند C)، دستور :keyword:`!for` پایتون روی آیتم‌های هر دنباله‌ای " +"(یک فهرست یا یک رشته) به ترتیبی که در دنباله ظاهر شده‌اند پیمایش می‌کند. برای " +"مثال (بدون قصد استعاره):" #: ../../tutorial/controlflow.rst:63 msgid "" @@ -101,6 +131,14 @@ msgid "" "window 6\n" "defenestrate 12" msgstr "" +">>> # اندازه‌گیری طول چند رشته:\n" +">>> words = ['cat', 'window', 'defenestrate']\n" +">>> for w in words:\n" +"... print(w, len(w))\n" +"...\n" +"cat 3\n" +"window 6\n" +"defenestrate 12" #: ../../tutorial/controlflow.rst:72 msgid "" @@ -108,6 +146,9 @@ msgid "" "can be tricky to get right. Instead, it is usually more straight-forward to " "loop over a copy of the collection or to create a new collection::" msgstr "" +"کدی که هنگام پیمایش روی یک مجموعه، همان مجموعه را تغییر می‌دهد، ممکن است " +"به‌درستی نوشتن دشوار باشد. در عوض، معمولاً ساده‌تر است که روی یک کپی از مجموعه " +"پیمایش کنید یا یک مجموعهٔ جدید ایجاد کنید::" #: ../../tutorial/controlflow.rst:76 msgid "" @@ -125,10 +166,23 @@ msgid "" " if status == 'active':\n" " active_users[user] = status" msgstr "" +"# ایجاد یک مجموعه‌ی نمونه\n" +"users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}\n" +"\n" +"# راهبرد: پیمایش روی یک کپی\n" +"for user, status in users.copy().items():\n" +" if status == 'inactive':\n" +" del users[user]\n" +"\n" +"# راهبرد: ایجاد یک مجموعه‌ی جدید\n" +"active_users = {}\n" +"for user, status in users.items():\n" +" if status == 'active':\n" +" active_users[user] = status" #: ../../tutorial/controlflow.rst:94 msgid "The :func:`range` Function" -msgstr "" +msgstr "تابع :func:`range`" #: ../../tutorial/controlflow.rst:96 msgid "" @@ -136,6 +190,8 @@ msgid "" "function :func:`range` comes in handy. It generates arithmetic " "progressions::" msgstr "" +"اگر واقعاً نیاز دارید روی یک دنباله از اعداد پیمایش کنید، تابع " +"داخلی :func:`range` بسیار کاربردی است. این تابع تصاعدهای حسابی تولید می‌کند::" #: ../../tutorial/controlflow.rst:99 msgid "" @@ -148,6 +204,14 @@ msgid "" "3\n" "4" msgstr "" +">>> for i in range(5):\n" +"... print(i)\n" +"...\n" +"0\n" +"1\n" +"2\n" +"3\n" +"4" #: ../../tutorial/controlflow.rst:108 msgid "" @@ -156,6 +220,10 @@ msgid "" "10. It is possible to let the range start at another number, or to specify " "a different increment (even negative; sometimes this is called the 'step')::" msgstr "" +"نقطهٔ پایانی داده‌شده هرگز بخشی از دنبالهٔ تولیدشده نیست؛ ``range(10)`` مقدار " +"تولید می‌کند که همان نمایه‌های مجاز برای آیتم‌های یک دنباله با طول ۱۰ هستند. " +"امکان این وجود دارد که شروع بازه را از عدد دیگری تعیین کنید، یا افزایشی " +"متفاوت (حتی منفی؛ که گاهی «گام» نامیده می‌شود) مشخص کنید::" #: ../../tutorial/controlflow.rst:113 msgid "" @@ -168,12 +236,22 @@ msgid "" ">>> list(range(-10, -100, -30))\n" "[-10, -40, -70]" msgstr "" +">>> list(range(5, 10))\n" +"[5, 6, 7, 8, 9]\n" +"\n" +">>> list(range(0, 10, 3))\n" +"[0, 3, 6, 9]\n" +"\n" +">>> list(range(-10, -100, -30))\n" +"[-10, -40, -70]" #: ../../tutorial/controlflow.rst:122 msgid "" "To iterate over the indices of a sequence, you can combine :func:`range` " "and :func:`len` as follows::" msgstr "" +"برای پیمایش روی نمایه‌های یک دنباله، می‌توانید :func:`range` و :func:`len` را " +"به شکل زیر ترکیب کنید::" #: ../../tutorial/controlflow.rst:125 msgid "" @@ -187,22 +265,35 @@ msgid "" "3 little\n" "4 lamb" msgstr "" +">>> a = ['Mary', 'had', 'a', 'little', 'lamb']\n" +">>> for i in range(len(a)):\n" +"... print(i, a[i])\n" +"...\n" +"0 Mary\n" +"1 had\n" +"2 a\n" +"3 little\n" +"4 lamb" #: ../../tutorial/controlflow.rst:135 msgid "" "In most such cases, however, it is convenient to use the :func:`enumerate` " "function, see :ref:`tut-loopidioms`." msgstr "" +"بااین‌حال، در بیشتر چنین مواردی استفاده از تابع :func:`enumerate` راحت‌تر است؛ " +"به :ref:`tut-loopidioms` مراجعه کنید." #: ../../tutorial/controlflow.rst:138 msgid "A strange thing happens if you just print a range::" -msgstr "" +msgstr "اگر فقط یک range را چاپ کنید، اتفاق عجیبی رخ می‌دهد::" #: ../../tutorial/controlflow.rst:140 msgid "" ">>> range(10)\n" "range(0, 10)" msgstr "" +">>> range(10)\n" +"range(0, 10)" #: ../../tutorial/controlflow.rst:143 msgid "" @@ -211,6 +302,10 @@ msgid "" "items of the desired sequence when you iterate over it, but it doesn't " "really make the list, thus saving space." msgstr "" +"از بسیاری جهات، شیئی که توسط :func:`range` برگردانده می‌شود طوری رفتار می‌کند " +"که گویی یک فهرست است، اما در واقع چنین نیست. این یک شیء است که هنگام پیمایش، " +"آیتم‌های متوالی دنبالهٔ موردنظر را برمی‌گرداند، اما واقعاً فهرست را ایجاد نمی‌کند " +"و در نتیجه در فضا صرفه‌جویی می‌شود." #: ../../tutorial/controlflow.rst:148 msgid "" @@ -220,12 +315,19 @@ msgid "" "the :keyword:`for` statement is such a construct, while an example of a " "function that takes an iterable is :func:`sum`::" msgstr "" +"می‌گوییم چنین شیئی :term:`iterable` است؛ یعنی برای استفاده به‌عنوان هدف تابع‌ها " +"و ساختارهایی مناسب است که انتظار دارند چیزی وجود داشته باشد که بتوانند از آن " +"آیتم‌های متوالی را تا زمانی که چیزی باقی نمانده است دریافت کنند. دیدیم که " +"دستور :keyword:`for` چنین ساختاری است، در حالی که نمونه‌ای از تابعی که یک شیء " +"قابل پیمایش دریافت می‌کند :func:`sum` است::" #: ../../tutorial/controlflow.rst:154 msgid "" ">>> sum(range(4)) # 0 + 1 + 2 + 3\n" "6" msgstr "" +">>> sum(range(4)) # 0 + 1 + 2 + 3\n" +"6" #: ../../tutorial/controlflow.rst:157 msgid "" @@ -233,16 +335,21 @@ msgid "" "arguments. In chapter :ref:`tut-structures`, we will discuss :func:`list` " "in more detail." msgstr "" +"بعداً تابع‌های بیشتری را خواهیم دید که اشیای قابل پیمایش برمی‌گردانند و اشیای " +"قابل پیمایش را به‌عنوان آرگومان دریافت می‌کنند. در فصل :ref:`tut-structures`، " +"دربارهٔ :func:`list` با جزئیات بیشتری صحبت خواهیم کرد." #: ../../tutorial/controlflow.rst:164 msgid ":keyword:`!break` and :keyword:`!continue` Statements" -msgstr "" +msgstr "دستورهای :keyword:`!break` و :keyword:`!continue`" #: ../../tutorial/controlflow.rst:166 msgid "" "The :keyword:`break` statement breaks out of the innermost " "enclosing :keyword:`for` or :keyword:`while` loop::" msgstr "" +"دستور :keyword:`break` از داخلی‌ترین حلقهٔ محصورکنندهٔ :keyword:`for` " +"یا :keyword:`while` خارج می‌شود::" #: ../../tutorial/controlflow.rst:169 msgid "" @@ -257,12 +364,22 @@ msgid "" "8 equals 2 * 4\n" "9 equals 3 * 3" msgstr "" +">>> for n in range(2, 10):\n" +"... for x in range(2, n):\n" +"... if n % x == 0:\n" +"... print(f\"{n} equals {x} * {n//x}\")\n" +"... break\n" +"...\n" +"4 equals 2 * 2\n" +"6 equals 2 * 3\n" +"8 equals 2 * 4\n" +"9 equals 3 * 3" #: ../../tutorial/controlflow.rst:180 msgid "" "The :keyword:`continue` statement continues with the next iteration of the " "loop::" -msgstr "" +msgstr "دستور :keyword:`continue` به تکرار بعدی حلقه ادامه می‌دهد::" #: ../../tutorial/controlflow.rst:183 msgid "" @@ -281,10 +398,24 @@ msgid "" "Found an even number 8\n" "Found an odd number 9" msgstr "" +">>> for num in range(2, 10):\n" +"... if num % 2 == 0:\n" +"... print(f\"Found an even number {num}\")\n" +"... continue\n" +"... print(f\"Found an odd number {num}\")\n" +"...\n" +"Found an even number 2\n" +"Found an odd number 3\n" +"Found an even number 4\n" +"Found an odd number 5\n" +"Found an even number 6\n" +"Found an odd number 7\n" +"Found an even number 8\n" +"Found an odd number 9" #: ../../tutorial/controlflow.rst:202 msgid ":keyword:`!else` Clauses on Loops" -msgstr "" +msgstr "بخش‌های :keyword:`!else` در حلقه‌ها" #: ../../tutorial/controlflow.rst:204 msgid "" @@ -293,18 +424,24 @@ msgid "" "finishes without executing the :keyword:`!break`, the :keyword:`!else` " "clause executes." msgstr "" +"در یک حلقهٔ :keyword:`!for` یا :keyword:`!while`، دستور :keyword:`!break` " +"می‌تواند با یک بخش :keyword:`!else` همراه شود. اگر حلقه بدون اجرای :keyword:`!" +"break` به پایان برسد، بخش :keyword:`!else` اجرا می‌شود." #: ../../tutorial/controlflow.rst:208 msgid "" "In a :keyword:`for` loop, the :keyword:`!else` clause is executed after the " "loop finishes its final iteration, that is, if no break occurred." msgstr "" +"در یک حلقهٔ :keyword:`for`، بخش :keyword:`!else` پس از پایان آخرین تکرار حلقه " +"اجرا می‌شود؛ یعنی زمانی که هیچ breakای رخ نداده باشد." #: ../../tutorial/controlflow.rst:211 msgid "" "In a :keyword:`while` loop, it's executed after the loop's condition becomes " "false." msgstr "" +"در یک حلقهٔ :keyword:`while`، این بخش پس از نادرست شدن شرط حلقه اجرا می‌شود." #: ../../tutorial/controlflow.rst:213 msgid "" @@ -313,12 +450,18 @@ msgid "" "ending the loop early, such as a :keyword:`return` or a raised exception, " "will also skip execution of the :keyword:`else` clause." msgstr "" +"در هر دو نوع حلقه، بخش :keyword:`!else` در صورتی **اجرا نمی‌شود** که حلقه " +"توسط یک :keyword:`break` خاتمه یافته باشد. البته روش‌های دیگر پایان زودهنگام " +"حلقه، مانند یک :keyword:`return` یا ایجاد شدن یک استثنا، نیز اجرای " +"بخش :keyword:`else` را رد می‌کنند." #: ../../tutorial/controlflow.rst:218 msgid "" "This is exemplified in the following :keyword:`!for` loop, which searches " "for prime numbers::" msgstr "" +"این موضوع در حلقهٔ :keyword:`!for` زیر نشان داده شده است که به دنبال اعداد " +"اول می‌گردد::" #: ../../tutorial/controlflow.rst:221 msgid "" @@ -340,12 +483,31 @@ msgid "" "8 equals 2 * 4\n" "9 equals 3 * 3" msgstr "" +">>> for n in range(2, 10):\n" +"... for x in range(2, n):\n" +"... if n % x == 0:\n" +"... print(n, 'equals', x, '*', n//x)\n" +"... break\n" +"... else:\n" +"... # حلقه بدون پیدا کردن هیچ مقسوم‌علیهی به پایان رسید\n" +"... print(n, 'is a prime number')\n" +"...\n" +"2 is a prime number\n" +"3 is a prime number\n" +"4 equals 2 * 2\n" +"5 is a prime number\n" +"6 equals 2 * 3\n" +"7 is a prime number\n" +"8 equals 2 * 4\n" +"9 equals 3 * 3" #: ../../tutorial/controlflow.rst:239 msgid "" "(Yes, this is the correct code. Look closely: the ``else`` clause belongs " "to the ``for`` loop, **not** the ``if`` statement.)" msgstr "" +"(بله، این کد درست است. با دقت نگاه کنید: بخش ``else`` به حلقهٔ ``for`` تعلق " +"دارد، **نه** به دستور ``if``.)" #: ../../tutorial/controlflow.rst:242 msgid "" @@ -355,6 +517,11 @@ msgid "" "condition is ever true, a ``break`` will happen. If the condition is never " "true, the ``else`` clause outside the loop will execute." msgstr "" +"یک راه برای فکر کردن دربارهٔ بخش else این است که تصور کنید با دستور ``if`` " +"داخل حلقه جفت شده است. هنگام اجرای حلقه، دنباله‌ای مانند if/if/if/else اجرا " +"می‌شود. دستور ``if`` داخل حلقه قرار دارد و چندین بار بررسی می‌شود. اگر شرط " +"هرگز درست شود، یک ``break`` رخ می‌دهد. اگر شرط هیچ‌گاه درست نشود، بخش ``else`` " +"خارج از حلقه اجرا خواهد شد." #: ../../tutorial/controlflow.rst:248 msgid "" @@ -365,16 +532,24 @@ msgid "" "occurs. For more on the ``try`` statement and exceptions, see :ref:`tut-" "handling`." msgstr "" +"هنگام استفاده از یک حلقه، بخش ``else`` شباهت بیشتری به بخش ``else`` " +"دستور :keyword:`try` دارد تا دستورهای ``if``: بخش ``else`` یک " +"دستور ``try`` زمانی اجرا می‌شود که هیچ استثنایی رخ ندهد، و بخش ``else`` یک " +"حلقه زمانی اجرا می‌شود که هیچ ``break``\ ای رخ ندهد. برای اطلاعات بیشتر دربارهٔ " +"دستور ``try`` و استثناها، به :ref:`tut-handling` مراجعه کنید." #: ../../tutorial/controlflow.rst:258 msgid ":keyword:`!pass` Statements" -msgstr "" +msgstr "دستورهای :keyword:`!pass`" #: ../../tutorial/controlflow.rst:260 msgid "" "The :keyword:`pass` statement does nothing. It can be used when a statement " "is required syntactically but the program requires no action. For example::" msgstr "" +"دستور :keyword:`pass` هیچ کاری انجام نمی‌دهد. زمانی می‌توان از آن استفاده کرد " +"که از نظر نحوی وجود یک دستور لازم باشد، اما برنامه به هیچ عملی نیاز نداشته " +"باشد. برای مثال::" #: ../../tutorial/controlflow.rst:263 msgid "" @@ -382,10 +557,13 @@ msgid "" "... pass # Busy-wait for keyboard interrupt (Ctrl+C)\n" "..." msgstr "" +">>> while True:\n" +"... pass # انتظار فعال برای وقفه‌ی صفحه‌کلید (Ctrl+C)\n" +"..." #: ../../tutorial/controlflow.rst:267 msgid "This is commonly used for creating minimal classes::" -msgstr "" +msgstr "این دستور معمولاً برای ایجاد کلاس‌های حداقلی استفاده می‌شود::" #: ../../tutorial/controlflow.rst:269 msgid "" @@ -393,6 +571,9 @@ msgid "" "... pass\n" "..." msgstr "" +">>> class MyEmptyClass:\n" +"... pass\n" +"..." #: ../../tutorial/controlflow.rst:273 msgid "" @@ -401,6 +582,10 @@ msgid "" "to keep thinking at a more abstract level. The :keyword:`!pass` is silently " "ignored::" msgstr "" +"جای دیگری که می‌توان از :keyword:`pass` استفاده کرد، به‌عنوان جای‌نگهدار برای " +"بدنهٔ یک تابع یا شرط در زمانی است که روی کد جدید کار می‌کنید؛ این کار به شما " +"اجازه می‌دهد در سطح انتزاعی‌تری به فکر کردن ادامه دهید. :keyword:`!pass` " +"به‌صورت بی‌صدا نادیده گرفته می‌شود::" #: ../../tutorial/controlflow.rst:277 msgid "" @@ -408,6 +593,9 @@ msgid "" "... pass # Remember to implement this!\n" "..." msgstr "" +">>> def initlog(*args):\n" +"... pass # فراموش نکنید این تابع را پیاده‌سازی کنید!\n" +"..." #: ../../tutorial/controlflow.rst:281 msgid "" @@ -417,10 +605,15 @@ msgid "" "but :code:`...` is used conventionally as a placeholder body as well. " "See :ref:`bltin-ellipsis-object`." msgstr "" +"برای حالت آخر، بسیاری از افراد به‌جای :code:`pass` از مقدار لفظی " +"بیضی :code:`...` استفاده می‌کنند. این استفاده هیچ معنای ویژه‌ای برای پایتون " +"ندارد و بخشی از تعریف زبان نیست (در اینجا می‌توانستید از هر عبارت ثابتی " +"استفاده کنید)، اما :code:`...` به‌صورت قراردادی به‌عنوان بدنهٔ جای‌نگهدار نیز " +"استفاده می‌شود. به :ref:`bltin-ellipsis-object` مراجعه کنید." #: ../../tutorial/controlflow.rst:291 msgid ":keyword:`!match` Statements" -msgstr "" +msgstr ":keyword:`!match` دستورات" #: ../../tutorial/controlflow.rst:293 msgid "" @@ -432,11 +625,19 @@ msgid "" "also extract components (sequence elements or object attributes) from the " "value into variables. If no case matches, none of the branches is executed." msgstr "" +"یک دستور :keyword:`match` یک عبارت را دریافت می‌کند و مقدار آن را با الگوهای " +"متوالی که در یک یا چند بلوک case ارائه شده‌اند مقایسه می‌کند. این دستور در " +"ظاهر شبیه دستور switch در C، Java یا JavaScript (و بسیاری از زبان‌های دیگر) " +"است، اما شباهت بیشتری به تطبیق الگو (*pattern matching*) در زبان‌هایی مانند " +"Rust یا Haskell دارد. تنها اولین الگویی که تطبیق پیدا کند اجرا می‌شود و این " +"دستور همچنین می‌تواند اجزا (عناصر دنباله یا ویژگی‌های شیء) را از مقدار استخراج " +"کرده و در متغیرها قرار دهد. اگر هیچ caseای تطبیق پیدا نکند، هیچ‌یک از شاخه‌ها " +"اجرا نمی‌شوند." #: ../../tutorial/controlflow.rst:302 msgid "" "The simplest form compares a subject value against one or more literals::" -msgstr "" +msgstr "ساده‌ترین شکل، یک مقدار موضوع را با یک یا چند مقدار لفظی مقایسه می‌کند::" #: ../../tutorial/controlflow.rst:304 msgid "" @@ -451,29 +652,46 @@ msgid "" " case _:\n" " return \"Something's wrong with the internet\"" msgstr "" +"def http_error(status):\n" +" match status:\n" +" case 400:\n" +" return \"Bad request\"\n" +" case 404:\n" +" return \"Not found\"\n" +" case 418:\n" +" return \"I'm a teapot\"\n" +" case _:\n" +" return \"Something's wrong with the internet\"" #: ../../tutorial/controlflow.rst:315 msgid "" "Note the last block: the \"variable name\" ``_`` acts as a *wildcard* and " "never fails to match." msgstr "" +"به آخرین بلوک توجه کنید: «نام متغیر» ``_`` به‌عنوان یک *wildcard* عمل می‌کند و " +"هرگز در تطبیق شکست نمی‌خورد." #: ../../tutorial/controlflow.rst:318 msgid "" "You can combine several literals in a single pattern using ``|`` (\"or\")::" msgstr "" +"می‌توانید چند مقدار لفظی را با استفاده از ``|`` («یا») در یک الگو ترکیب کنید::" #: ../../tutorial/controlflow.rst:320 msgid "" "case 401 | 403 | 404:\n" " return \"Not allowed\"" msgstr "" +"case 401 | 403 | 404:\n" +" return \"Not allowed\"" #: ../../tutorial/controlflow.rst:323 msgid "" "Patterns can look like unpacking assignments, and can be used to bind " "variables::" msgstr "" +"الگوها می‌توانند شبیه انتساب‌های بازکردن بسته (*unpacking assignments*) باشند " +"و برای مقداردهی به متغیرها استفاده شوند::" #: ../../tutorial/controlflow.rst:326 msgid "" @@ -490,6 +708,18 @@ msgid "" " case _:\n" " raise ValueError(\"Not a point\")" msgstr "" +"# نقطه یک تاپل (x, y) است\n" +"match point:\n" +" case (0, 0):\n" +" print(\"Origin\")\n" +" case (0, y):\n" +" print(f\"Y={y}\")\n" +" case (x, 0):\n" +" print(f\"X={x}\")\n" +" case (x, y):\n" +" print(f\"X={x}, Y={y}\")\n" +" case _:\n" +" raise ValueError(\"Not a point\")" #: ../../tutorial/controlflow.rst:339 msgid "" @@ -500,6 +730,11 @@ msgid "" "which makes it conceptually similar to the unpacking assignment ``(x, y) = " "point``." msgstr "" +"این مورد را با دقت بررسی کنید! الگوی اول دو مقدار لفظی دارد و می‌توان آن را " +"گسترشی از الگوی لفظی نشان‌داده‌شده در بالا در نظر گرفت. اما دو الگوی بعدی یک " +"مقدار لفظی و یک متغیر را ترکیب می‌کنند، و متغیر یک مقدار را از موضوع " +"(``point``) *دریافت* می‌کند. الگوی چهارم دو مقدار را دریافت می‌کند، که از نظر " +"مفهومی شبیه به انتساب بازکردن بستهٔ ``(x, y) = point`` است." #: ../../tutorial/controlflow.rst:346 msgid "" @@ -507,6 +742,9 @@ msgid "" "followed by an argument list resembling a constructor, but with the ability " "to capture attributes into variables::" msgstr "" +"اگر برای ساختاربندی داده‌های خود از کلاس‌ها استفاده می‌کنید، می‌توانید نام کلاس " +"را به‌همراه فهرستی از آرگومان‌ها که شبیه سازنده است استفاده کنید، اما با " +"قابلیت دریافت ویژگی‌ها در متغیرها::" #: ../../tutorial/controlflow.rst:350 msgid "" @@ -528,6 +766,23 @@ msgid "" " case _:\n" " print(\"Not a point\")" msgstr "" +"class Point:\n" +" def __init__(self, x, y):\n" +" self.x = x\n" +" self.y = y\n" +"\n" +"def where_is(point):\n" +" match point:\n" +" case Point(x=0, y=0):\n" +" print(\"Origin\")\n" +" case Point(x=0, y=y):\n" +" print(f\"Y={y}\")\n" +" case Point(x=x, y=0):\n" +" print(f\"X={x}\")\n" +" case Point():\n" +" print(\"Somewhere else\")\n" +" case _:\n" +" print(\"Not a point\")" #: ../../tutorial/controlflow.rst:368 msgid "" @@ -538,6 +793,12 @@ msgid "" "\"y\"), the following patterns are all equivalent (and all bind the ``y`` " "attribute to the ``var`` variable)::" msgstr "" +"می‌توانید از پارامترهای موقعیتی با برخی کلاس‌های داخلی که برای ویژگی‌های خود " +"ترتیب مشخصی ارائه می‌کنند (برای مثال dataclassها) استفاده کنید. همچنین " +"می‌توانید با تنظیم ویژگی ویژهٔ ``__match_args__`` در کلاس‌های خود، موقعیت مشخصی " +"برای ویژگی‌ها در الگوها تعریف کنید. اگر این ویژگی روی (\"x\", \"y\") تنظیم " +"شده باشد، الگوهای زیر همگی معادل هستند (و همگی ویژگی ``y`` را در متغیر " +"``var`` قرار می‌دهند)::" #: ../../tutorial/controlflow.rst:374 msgid "" @@ -546,6 +807,10 @@ msgid "" "Point(x=1, y=var)\n" "Point(y=var, x=1)" msgstr "" +"Point(1, var)\n" +"Point(1, y=var)\n" +"Point(x=1, y=var)\n" +"Point(y=var, x=1)" #: ../../tutorial/controlflow.rst:379 msgid "" @@ -557,12 +822,21 @@ msgid "" "(recognized by the \"(...)\" next to them like ``Point`` above) are never " "assigned to." msgstr "" +"روش پیشنهادی برای خواندن الگوها این است که آن‌ها را شکل گسترش‌یافته‌ای از چیزی " +"در نظر بگیرید که در سمت چپ یک انتساب قرار می‌دهید، تا متوجه شوید چه متغیرهایی " +"با چه مقادیری تنظیم خواهند شد. تنها نام‌های مستقل (مانند ``var`` در بالا) " +"توسط دستور match مقداردهی می‌شوند. نام‌های نقطه‌ای (مانند ``foo.bar``)، نام " +"ویژگی‌ها (مانند ``x=`` و ``y=`` در بالا) یا نام کلاس‌ها (که با (...) کنار " +"آن‌ها، مانند ``Point`` در بالا، شناخته می‌شوند) هرگز مقداردهی نمی‌شوند." #: ../../tutorial/controlflow.rst:386 msgid "" "Patterns can be arbitrarily nested. For example, if we have a short list of " "Points, with ``__match_args__`` added, we could match it like this::" msgstr "" +"الگوها می‌توانند به‌صورت دلخواه تو‌در‌تو باشند. برای مثال، اگر یک فهرست کوتاه از " +"Pointها داشته باشیم و ``__match_args__`` را به آن‌ها اضافه کرده باشیم، " +"می‌توانیم آن را به این شکل تطبیق دهیم::" #: ../../tutorial/controlflow.rst:389 msgid "" @@ -584,6 +858,23 @@ msgid "" " case _:\n" " print(\"Something else\")" msgstr "" +"class Point:\n" +" __match_args__ = ('x', 'y')\n" +" def __init__(self, x, y):\n" +" self.x = x\n" +" self.y = y\n" +"\n" +"match points:\n" +" case []:\n" +" print(\"No points\")\n" +" case [Point(0, 0)]:\n" +" print(\"The origin\")\n" +" case [Point(x, y)]:\n" +" print(f\"Single point {x}, {y}\")\n" +" case [Point(0, y1), Point(0, y2)]:\n" +" print(f\"Two on the Y axis at {y1}, {y2}\")\n" +" case _:\n" +" print(\"Something else\")" #: ../../tutorial/controlflow.rst:407 msgid "" @@ -591,6 +882,9 @@ msgid "" "guard is false, ``match`` goes on to try the next case block. Note that " "value capture happens before the guard is evaluated::" msgstr "" +"می‌توانیم یک بخش ``if`` به یک الگو اضافه کنیم که به آن «نگهبان» (*guard*) " +"گفته می‌شود. اگر نگهبان نادرست باشد، ``match`` به تلاش برای بلوک case بعدی " +"ادامه می‌دهد. توجه کنید که دریافت مقدار پیش از ارزیابی نگهبان انجام می‌شود::" #: ../../tutorial/controlflow.rst:411 msgid "" @@ -600,10 +894,15 @@ msgid "" " case Point(x, y):\n" " print(f\"Not on the diagonal\")" msgstr "" +"match point:\n" +" case Point(x, y) if x == y:\n" +" print(f\"Y=X at {x}\")\n" +" case Point(x, y):\n" +" print(f\"Not on the diagonal\")" #: ../../tutorial/controlflow.rst:417 msgid "Several other key features of this statement:" -msgstr "" +msgstr "چند ویژگی کلیدی دیگر این دستور:" #: ../../tutorial/controlflow.rst:419 msgid "" @@ -611,6 +910,9 @@ msgid "" "meaning and actually match arbitrary sequences. An important exception is " "that they don't match iterators or strings." msgstr "" +"مانند انتساب‌های بازکردن بسته، الگوهای تاپل و فهرست دقیقاً معنای یکسانی دارند " +"و در واقع با دنباله‌های دلخواه تطبیق پیدا می‌کنند. یک استثنای مهم این است که " +"آن‌ها با تکرارگرها یا رشته‌ها تطبیق پیدا نمی‌کنند." #: ../../tutorial/controlflow.rst:423 msgid "" @@ -619,6 +921,10 @@ msgid "" "also be ``_``, so ``(x, y, *_)`` matches a sequence of at least two items " "without binding the remaining items." msgstr "" +"الگوهای دنباله‌ای از بازکردن بستهٔ گسترده پشتیبانی می‌کنند: ``[x, y, *rest]`` و " +"``(x, y, *rest)`` مشابه انتساب‌های بازکردن بسته عمل می‌کنند. نام پس از ``*`` " +"نیز می‌تواند ``_`` باشد، بنابراین ``(x, y, *_)`` با دنباله‌ای دارای حداقل دو " +"آیتم تطبیق پیدا می‌کند، بدون اینکه آیتم‌های باقی‌مانده را در متغیری قرار دهد." #: ../../tutorial/controlflow.rst:428 msgid "" @@ -627,32 +933,42 @@ msgid "" "sequence patterns, extra keys are ignored. An unpacking like ``**rest`` is " "also supported. (But ``**_`` would be redundant, so it is not allowed.)" msgstr "" +"الگوهای نگاشتی: ``{\"bandwidth\": b, \"latency\": l}`` مقادیر " +"``\"bandwidth\"`` و ``\"latency\"`` را از یک فرهنگ لغت دریافت می‌کند. برخلاف " +"الگوهای دنباله‌ای، کلیدهای اضافی نادیده گرفته می‌شوند. بازکردن بسته‌ای مانند " +"``**rest`` نیز پشتیبانی می‌شود. (اما ``**_`` اضافی است، بنابراین مجاز نیست.)" #: ../../tutorial/controlflow.rst:433 msgid "Subpatterns may be captured using the ``as`` keyword::" -msgstr "" +msgstr "زیرالگوها را می‌توان با استفاده از کلیدواژهٔ ``as`` دریافت کرد::" #: ../../tutorial/controlflow.rst:435 msgid "case (Point(x1, y1), Point(x2, y2) as p2): ..." -msgstr "" +msgstr "case (Point(x1, y1), Point(x2, y2) as p2): ..." #: ../../tutorial/controlflow.rst:437 msgid "" "will capture the second element of the input as ``p2`` (as long as the input " "is a sequence of two points)" msgstr "" +"عنصر دوم ورودی را به‌عنوان ``p2`` دریافت می‌کند (تا زمانی که ورودی یک دنبالهٔ " +"دو عضوی از نقاط باشد)" #: ../../tutorial/controlflow.rst:440 msgid "" "Most literals are compared by equality, however the singletons ``True``, " "``False`` and ``None`` are compared by identity." msgstr "" +"بیشتر مقادیر لفظی با استفاده از برابری مقایسه می‌شوند، اما تک‌نمونه‌های " +"``True``، ``False`` و ``None`` با استفاده از هویت مقایسه می‌شوند." #: ../../tutorial/controlflow.rst:443 msgid "" "Patterns may use named constants. These must be dotted names to prevent " "them from being interpreted as capture variables::" msgstr "" +"الگوها می‌توانند از ثابت‌های نام‌گذاری‌شده استفاده کنند. این‌ها باید نام‌های " +"نقطه‌ای باشند تا از تفسیر شدن آن‌ها به‌عنوان متغیرهای دریافت‌کننده جلوگیری شود::" #: ../../tutorial/controlflow.rst:446 msgid "" @@ -672,22 +988,40 @@ msgid "" " case Color.BLUE:\n" " print(\"I'm feeling the blues :(\")" msgstr "" +"from enum import Enum\n" +"class Color(Enum):\n" +" RED = 'red'\n" +" GREEN = 'green'\n" +" BLUE = 'blue'\n" +"\n" +"color = Color(input(\"Enter your choice of 'red', 'blue' or 'green': \"))\n" +"\n" +"match color:\n" +" case Color.RED:\n" +" print(\"I see red!\")\n" +" case Color.GREEN:\n" +" print(\"Grass is green\")\n" +" case Color.BLUE:\n" +" print(\"I'm feeling the blues :(\")" #: ../../tutorial/controlflow.rst:462 msgid "" "For a more detailed explanation and additional examples, you can look " "into :pep:`636` which is written in a tutorial format." msgstr "" +"برای توضیح دقیق‌تر و نمونه‌های بیشتر، می‌توانید به :pep:`636` مراجعه کنید که با " +"قالب یک آموزش نوشته شده است." #: ../../tutorial/controlflow.rst:468 msgid "Defining Functions" -msgstr "" +msgstr "تعریف توابع" #: ../../tutorial/controlflow.rst:470 msgid "" "We can create a function that writes the Fibonacci series to an arbitrary " "boundary::" msgstr "" +"می‌توانیم تابعی ایجاد کنیم که سری فیبوناچی را تا یک کران دلخواه بنویسد::" #: ../../tutorial/controlflow.rst:473 msgid "" @@ -703,6 +1037,17 @@ msgid "" ">>> fib(2000)\n" "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597" msgstr "" +">>> def fib(n): # نوشتن دنباله‌ی فیبوناچی کوچک‌تر از n\n" +"... \"\"\"Print a Fibonacci series less than n.\"\"\"\n" +"... a, b = 0, 1\n" +"... while a < n:\n" +"... print(a, end=' ')\n" +"... a, b = b, a+b\n" +"... print()\n" +"...\n" +">>> # اکنون تابعی را که تعریف کردیم فراخوانی می‌کنیم:\n" +">>> fib(2000)\n" +"0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597" #: ../../tutorial/controlflow.rst:490 msgid "" @@ -711,6 +1056,9 @@ msgid "" "parameters. The statements that form the body of the function start at the " "next line, and must be indented." msgstr "" +"کلیدواژهٔ :keyword:`def` یک *تعریف تابع* را معرفی می‌کند. این کلیدواژه باید پس " +"از خود نام تابع و فهرست پارامترهای رسمی درون پرانتز بیاید. دستورهایی که بدنهٔ " +"تابع را تشکیل می‌دهند از خط بعدی شروع می‌شوند و باید تورفتگی داشته باشند." #: ../../tutorial/controlflow.rst:495 msgid "" @@ -722,6 +1070,13 @@ msgid "" "interactively browse through code; it's good practice to include docstrings " "in code that you write, so make a habit of it." msgstr "" +"اولین دستور بدنهٔ تابع می‌تواند به‌صورت اختیاری یک رشتهٔ لفظی باشد؛ این رشتهٔ " +"لفظی، رشتهٔ مستندات تابع یا :dfn:`docstring` است. (اطلاعات بیشتر دربارهٔ " +"رشته‌های مستندات را می‌توانید در بخش :ref:`tut-docstrings` پیدا کنید.) " +"ابزارهایی وجود دارند که از docstringها برای تولید خودکار مستندات آنلاین یا " +"چاپی، یا برای اجازه دادن به کاربر جهت مرور تعاملی کد استفاده می‌کنند؛ بهتر " +"است در کدی که می‌نویسید docstringها را قرار دهید، بنابراین آن را به یک عادت " +"تبدیل کنید." #: ../../tutorial/controlflow.rst:502 msgid "" @@ -736,6 +1091,15 @@ msgid "" "for variables of enclosing functions, named in a :keyword:`nonlocal` " "statement), although they may be referenced." msgstr "" +"*اجرای* یک تابع، یک جدول نماد جدید ایجاد می‌کند که برای متغیرهای محلی تابع " +"استفاده می‌شود. به‌طور دقیق‌تر، تمام انتساب‌های متغیر در یک تابع، مقدار را در " +"جدول نماد محلی ذخیره می‌کنند؛ در حالی که ارجاع‌های متغیر ابتدا در جدول نماد " +"محلی، سپس در جدول‌های نماد محلی تابع‌های دربرگیرنده، سپس در جدول نماد سراسری، " +"و در نهایت در جدول نام‌های داخلی جست‌وجو می‌شوند. بنابراین، متغیرهای سراسری و " +"متغیرهای تابع‌های دربرگیرنده نمی‌توانند مستقیماً درون یک تابع مقداردهی شوند " +"(مگر اینکه برای متغیرهای سراسری با یک دستور :keyword:`global`، یا برای " +"متغیرهای تابع‌های دربرگیرنده با یک دستور :keyword:`nonlocal` نام‌گذاری شده " +"باشند)، اگرچه می‌توان به آن‌ها ارجاع داد." #: ../../tutorial/controlflow.rst:513 msgid "" @@ -746,6 +1110,12 @@ msgid "" "another function, or calls itself recursively, a new local symbol table is " "created for that call." msgstr "" +"پارامترهای واقعی (آرگومان‌ها) در یک فراخوانی تابع، هنگام فراخوانی تابع در " +"جدول نماد محلی تابع فراخوانی‌شده قرار می‌گیرند؛ بنابراین، آرگومان‌ها با استفاده " +"از *انتقال با مقدار* (*call by value*) ارسال می‌شوند (که در آن *مقدار* همیشه " +"یک ارجاع به شیء است، نه مقدار خود شیء). [#]_ هنگامی که یک تابع، تابع دیگری " +"را فراخوانی می‌کند یا به‌صورت بازگشتی خودش را فراخوانی می‌کند، یک جدول نماد " +"محلی جدید برای آن فراخوانی ایجاد می‌شود." #: ../../tutorial/controlflow.rst:520 msgid "" @@ -754,6 +1124,10 @@ msgid "" "to by that name as a user-defined function. Other names can also point to " "that same function object and can also be used to access the function::" msgstr "" +"یک تعریف تابع، نام تابع را با شیء تابع در جدول نماد فعلی مرتبط می‌کند. مفسر " +"شیئی را که آن نام به آن اشاره می‌کند به‌عنوان یک تابع تعریف‌شده توسط کاربر " +"تشخیص می‌دهد. نام‌های دیگر نیز می‌توانند به همان شیء تابع اشاره کنند و برای " +"دسترسی به تابع استفاده شوند::" #: ../../tutorial/controlflow.rst:525 msgid "" @@ -763,6 +1137,11 @@ msgid "" ">>> f(100)\n" "0 1 1 2 3 5 8 13 21 34 55 89" msgstr "" +">>> fib\n" +"\n" +">>> f = fib\n" +">>> f(100)\n" +"0 1 1 2 3 5 8 13 21 34 55 89" #: ../../tutorial/controlflow.rst:531 msgid "" @@ -774,6 +1153,13 @@ msgid "" "the only value written. You can see it if you really want to " "using :func:`print`::" msgstr "" +"اگر از زبان‌های دیگر آمده باشید، ممکن است اعتراض کنید که ``fib`` یک تابع " +"نیست، بلکه یک رویه (*procedure*) است، زیرا مقداری برنمی‌گرداند. در واقع، حتی " +"تابع‌هایی که دستور :keyword:`return` ندارند نیز یک مقدار برمی‌گردانند، هرچند " +"مقدار نسبتاً بی‌اهمیتی است. این مقدار ``None`` نام دارد (که یک نام داخلی است). " +"نوشتن مقدار ``None`` معمولاً توسط مفسر حذف می‌شود اگر تنها مقداری باشد که قرار " +"است نوشته شود. اگر واقعاً بخواهید می‌توانید آن را با استفاده از :func:`print` " +"ببینید::" #: ../../tutorial/controlflow.rst:538 msgid "" @@ -781,12 +1167,17 @@ msgid "" ">>> print(fib(0))\n" "None" msgstr "" +">>> fib(0)\n" +">>> print(fib(0))\n" +"None" #: ../../tutorial/controlflow.rst:542 msgid "" "It is simple to write a function that returns a list of the numbers of the " "Fibonacci series, instead of printing it::" msgstr "" +"نوشتن تابعی که به‌جای چاپ کردن سری فیبوناچی، فهرستی از اعداد آن را برگرداند " +"ساده است::" #: ../../tutorial/controlflow.rst:545 msgid "" @@ -803,10 +1194,22 @@ msgid "" ">>> f100 # write the result\n" "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]" msgstr "" +">>> def fib2(n): # بازگرداندن دنباله‌ی فیبوناچی تا n\n" +"... \"\"\"Return a list containing the Fibonacci series up to n.\"\"\"\n" +"... result = []\n" +"... a, b = 0, 1\n" +"... while a < n:\n" +"... result.append(a) # توضیح زیر را ببینید\n" +"... a, b = b, a+b\n" +"... return result\n" +"...\n" +">>> f100 = fib2(100) # فراخوانی تابع\n" +">>> f100 # نمایش نتیجه\n" +"[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]" #: ../../tutorial/controlflow.rst:558 msgid "This example, as usual, demonstrates some new Python features:" -msgstr "" +msgstr "این مثال، مانند همیشه، چند ویژگی جدید پایتون را نشان می‌دهد:" #: ../../tutorial/controlflow.rst:560 msgid "" @@ -814,6 +1217,9 @@ msgid "" "function. :keyword:`!return` without an expression argument returns " "``None``. Falling off the end of a function also returns ``None``." msgstr "" +"دستور :keyword:`return` یک مقدار را از یک تابع برمی‌گرداند. :keyword:`!" +"return` بدون یک آرگومان عبارت، ``None`` را برمی‌گرداند. رسیدن به انتهای یک " +"تابع نیز ``None`` را برمی‌گرداند." #: ../../tutorial/controlflow.rst:564 msgid "" @@ -829,20 +1235,32 @@ msgid "" "In this example it is equivalent to ``result = result + [a]``, but more " "efficient." msgstr "" +"دستور ``result.append(a)`` یک *متد* از شیء فهرست ``result`` را فراخوانی " +"می‌کند. یک متد تابعی است که به یک شیء «تعلق دارد» و با قالب " +"``obj.methodname`` نام‌گذاری می‌شود؛ در اینجا ``obj`` یک شیء (که می‌تواند یک " +"عبارت باشد) و ``methodname`` نام متدی است که توسط نوع شیء تعریف شده است. " +"نوع‌های مختلف، متدهای متفاوتی تعریف می‌کنند. متدهای نوع‌های مختلف می‌توانند نام " +"یکسانی داشته باشند، بدون اینکه ابهامی ایجاد شود. (می‌توان با استفاده از " +"*کلاس‌ها* نوع‌ها و متدهای شیء سفارشی خود را تعریف کرد؛ به :ref:`tut-classes` " +"مراجعه کنید.) متد :meth:`~list.append` که در مثال نشان داده شده است برای " +"اشیای فهرست تعریف شده است؛ این متد یک عنصر جدید را به انتهای فهرست اضافه " +"می‌کند. در این مثال، معادل ``result = result + [a]`` است، اما کارآمدتر است." #: ../../tutorial/controlflow.rst:579 msgid "More on Defining Functions" -msgstr "" +msgstr "اطلاعات بیشتر دربارهٔ تعریف تابع‌ها" #: ../../tutorial/controlflow.rst:581 msgid "" "It is also possible to define functions with a variable number of arguments. " "There are three forms, which can be combined." msgstr "" +"همچنین امکان تعریف تابع‌هایی با تعداد متغیری از آرگومان‌ها وجود دارد. سه شکل " +"وجود دارد که می‌توان آن‌ها را با یکدیگر ترکیب کرد." #: ../../tutorial/controlflow.rst:588 msgid "Default Argument Values" -msgstr "" +msgstr "مقدارهای پیش‌فرض آرگومان‌ها" #: ../../tutorial/controlflow.rst:590 msgid "" @@ -850,6 +1268,9 @@ msgid "" "arguments. This creates a function that can be called with fewer arguments " "than it is defined to allow. For example::" msgstr "" +"کاربردی‌ترین شکل، مشخص کردن یک مقدار پیش‌فرض برای یک یا چند آرگومان است. این " +"کار تابعی ایجاد می‌کند که می‌توان آن را با آرگومان‌های کمتری نسبت به تعداد " +"تعریف‌شده فراخوانی کرد. برای مثال::" #: ../../tutorial/controlflow.rst:594 msgid "" @@ -865,39 +1286,57 @@ msgid "" " raise ValueError('invalid user response')\n" " print(reminder)" msgstr "" +"def ask_ok(prompt, retries=4, reminder='Please try again!'):\n" +" while True:\n" +" reply = input(prompt)\n" +" if reply in {'y', 'ye', 'yes'}:\n" +" return True\n" +" if reply in {'n', 'no', 'nop', 'nope'}:\n" +" return False\n" +" retries = retries - 1\n" +" if retries < 0:\n" +" raise ValueError('invalid user response')\n" +" print(reminder)" #: ../../tutorial/controlflow.rst:606 msgid "This function can be called in several ways:" -msgstr "" +msgstr "این تابع را می‌توان به چند روش فراخوانی کرد:" #: ../../tutorial/controlflow.rst:608 msgid "" "giving only the mandatory argument: ``ask_ok('Do you really want to quit?')``" -msgstr "" +msgstr "فقط با دادن آرگومان اجباری: ``ask_ok('Do you really want to quit?')``" #: ../../tutorial/controlflow.rst:610 msgid "" "giving one of the optional arguments: ``ask_ok('OK to overwrite the file?', " "2)``" msgstr "" +"با دادن یکی از آرگومان‌های اختیاری: ``ask_ok('OK to overwrite the file?', 2)``" #: ../../tutorial/controlflow.rst:612 msgid "" "or even giving all arguments: ``ask_ok('OK to overwrite the file?', 2, 'Come " "on, only yes or no!')``" msgstr "" +"یا حتی با دادن همهٔ آرگومان‌ها: ``ask_ok('OK to overwrite the file?', 2, 'Come " +"on, only yes or no!')``" #: ../../tutorial/controlflow.rst:615 msgid "" "This example also introduces the :keyword:`in` keyword. This tests whether " "or not a sequence contains a certain value." msgstr "" +"این مثال همچنین کلیدواژهٔ :keyword:`in` را معرفی می‌کند. این کلیدواژه بررسی " +"می‌کند که آیا یک دنباله مقدار مشخصی را در خود دارد یا خیر." #: ../../tutorial/controlflow.rst:618 msgid "" "The default values are evaluated at the point of function definition in the " "*defining* scope, so that ::" msgstr "" +"مقدارهای پیش‌فرض در نقطهٔ تعریف تابع و در محدودهٔ *تعریف‌کننده* (*defining " +"scope*) ارزیابی می‌شوند، بنابراین ::" #: ../../tutorial/controlflow.rst:621 msgid "" @@ -909,10 +1348,17 @@ msgid "" "i = 6\n" "f()" msgstr "" +"i = 5\n" +"\n" +"def f(arg=i):\n" +" print(arg)\n" +"\n" +"i = 6\n" +"f()" #: ../../tutorial/controlflow.rst:629 msgid "will print ``5``." -msgstr "" +msgstr "``5`` را چاپ خواهد کرد." #: ../../tutorial/controlflow.rst:631 msgid "" @@ -921,6 +1367,10 @@ msgid "" "dictionary, or instances of most classes. For example, the following " "function accumulates the arguments passed to it on subsequent calls::" msgstr "" +"**هشدار مهم:** مقدار پیش‌فرض فقط یک‌بار ارزیابی می‌شود. این موضوع زمانی تفاوت " +"ایجاد می‌کند که مقدار پیش‌فرض یک شیء قابل تغییر مانند یک فهرست، فرهنگ لغت، یا " +"نمونه‌ای از بیشتر کلاس‌ها باشد. برای مثال، تابع زیر آرگومان‌هایی را که در " +"فراخوانی‌های بعدی به آن داده می‌شوند جمع‌آوری می‌کند::" #: ../../tutorial/controlflow.rst:636 msgid "" @@ -932,10 +1382,17 @@ msgid "" "print(f(2))\n" "print(f(3))" msgstr "" +"def f(a, L=[]):\n" +" L.append(a)\n" +" return L\n" +"\n" +"print(f(1))\n" +"print(f(2))\n" +"print(f(3))" #: ../../tutorial/controlflow.rst:644 msgid "This will print ::" -msgstr "" +msgstr "این دستور چاپ خواهد کرد ::" #: ../../tutorial/controlflow.rst:646 msgid "" @@ -943,12 +1400,17 @@ msgid "" "[1, 2]\n" "[1, 2, 3]" msgstr "" +"[1]\n" +"[1, 2]\n" +"[1, 2, 3]" #: ../../tutorial/controlflow.rst:650 msgid "" "If you don't want the default to be shared between subsequent calls, you can " "write the function like this instead::" msgstr "" +"اگر نمی‌خواهید مقدار پیش‌فرض بین فراخوانی‌های بعدی به اشتراک گذاشته شود، " +"می‌توانید تابع را به این شکل بنویسید::" #: ../../tutorial/controlflow.rst:653 msgid "" @@ -958,10 +1420,15 @@ msgid "" " L.append(a)\n" " return L" msgstr "" +"def f(a, L=None):\n" +" if L is None:\n" +" L = []\n" +" L.append(a)\n" +" return L" #: ../../tutorial/controlflow.rst:663 msgid "Keyword Arguments" -msgstr "" +msgstr "آرگومان‌های کلیدواژه‌ای" #: ../../tutorial/controlflow.rst:665 msgid "" @@ -969,6 +1436,8 @@ msgid "" "argument>` of the form ``kwarg=value``. For instance, the following " "function::" msgstr "" +"تابع‌ها همچنین می‌توانند با استفاده از :term:`keyword arguments ` به شکل ``kwarg=value`` فراخوانی شوند. برای نمونه، تابع زیر::" #: ../../tutorial/controlflow.rst:668 msgid "" @@ -978,6 +1447,11 @@ msgid "" " print(\"-- Lovely plumage, the\", type)\n" " print(\"-- It's\", state, \"!\")" msgstr "" +"def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):\n" +" print(\"-- This parrot wouldn't\", action, end=' ')\n" +" print(\"if you put\", voltage, \"volts through it.\")\n" +" print(\"-- Lovely plumage, the\", type)\n" +" print(\"-- It's\", state, \"!\")" #: ../../tutorial/controlflow.rst:674 msgid "" @@ -985,6 +1459,9 @@ msgid "" "(``state``, ``action``, and ``type``). This function can be called in any " "of the following ways::" msgstr "" +"یک آرگومان اجباری (``voltage``) و سه آرگومان اختیاری (``state``، ``action`` " +"و ``type``) را می‌پذیرد. این تابع می‌تواند به هر یک از روش‌های زیر فراخوانی " +"شود::" #: ../../tutorial/controlflow.rst:678 msgid "" @@ -998,10 +1475,17 @@ msgid "" "parrot('a thousand', state='pushing up the daisies') # 1 positional, 1 " "keyword" msgstr "" +"parrot(1000) # یک آرگومان موقعیتی\n" +"parrot(voltage=1000) # یک آرگومان کلیدی\n" +"parrot(voltage=1000000, action='VOOOOOM') # دو آرگومان کلیدی\n" +"parrot(action='VOOOOOM', voltage=1000000) # دو آرگومان کلیدی\n" +"parrot('a million', 'bereft of life', 'jump') # سه آرگومان موقعیتی\n" +"parrot('a thousand', state='pushing up the daisies') # یک آرگومان موقعیتی، " +"یک آرگومان کلیدی" #: ../../tutorial/controlflow.rst:685 msgid "but all the following calls would be invalid::" -msgstr "" +msgstr "اما تمام فراخوانی‌های زیر نامعتبر خواهند بود::" #: ../../tutorial/controlflow.rst:687 msgid "" @@ -1011,6 +1495,11 @@ msgid "" "parrot(110, voltage=220) # duplicate value for the same argument\n" "parrot(actor='John Cleese') # unknown keyword argument" msgstr "" +"parrot() # آرگومان الزامی وارد نشده است\n" +"parrot(voltage=5.0, 'dead') # آرگومان غیرکلیدی پس از آرگومان کلیدی آمده " +"است\n" +"parrot(110, voltage=220) # مقدار تکراری برای یک آرگومان یکسان\n" +"parrot(actor='John Cleese') # آرگومان کلیدی ناشناخته" #: ../../tutorial/controlflow.rst:692 msgid "" @@ -1022,6 +1511,13 @@ msgid "" "may receive a value more than once. Here's an example that fails due to this " "restriction::" msgstr "" +"در یک فراخوانی تابع، آرگومان‌های کلیدواژه‌ای باید پس از آرگومان‌های موقعیتی " +"بیایند. تمام آرگومان‌های کلیدواژه‌ای ارسال‌شده باید با یکی از آرگومان‌های " +"پذیرفته‌شده توسط تابع مطابقت داشته باشند (برای مثال، ``actor`` یک آرگومان " +"معتبر برای تابع ``parrot`` نیست)، و ترتیب آن‌ها اهمیتی ندارد. این موضوع شامل " +"آرگومان‌های غیر‌اختیاری نیز می‌شود (برای مثال، ``parrot(voltage=1000)`` نیز " +"معتبر است). هیچ آرگومانی نمی‌تواند بیش از یک‌بار مقدار دریافت کند. در اینجا " +"مثالی وجود دارد که به دلیل این محدودیت شکست می‌خورد::" #: ../../tutorial/controlflow.rst:700 msgid "" @@ -1033,6 +1529,13 @@ msgid "" " File \"\", line 1, in \n" "TypeError: function() got multiple values for argument 'a'" msgstr "" +">>> def function(a):\n" +"... pass\n" +"...\n" +">>> function(0, a=0)\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: function() got multiple values for argument 'a'" #: ../../tutorial/controlflow.rst:708 msgid "" @@ -1044,6 +1547,14 @@ msgid "" "positional arguments beyond the formal parameter list. (``*name`` must " "occur before ``**name``.) For example, if we define a function like this::" msgstr "" +"هنگامی که یک پارامتر رسمی نهایی به شکل ``**name`` وجود داشته باشد، یک فرهنگ " +"لغت (به :ref:`typesmapping` مراجعه کنید) دریافت می‌کند که شامل تمام " +"آرگومان‌های کلیدواژه‌ای است، به‌جز آن‌هایی که متناظر با یک پارامتر رسمی هستند. " +"این مورد می‌تواند با یک پارامتر رسمی به شکل ``*name`` ترکیب شود (که در زیربخش " +"بعدی توضیح داده شده است)؛ این پارامتر یک :ref:`tuple ` دریافت " +"می‌کند که شامل آرگومان‌های موقعیتی فراتر از فهرست پارامترهای رسمی است. " +"(``*name`` باید پیش از ``**name`` قرار گیرد.) برای مثال، اگر تابعی مانند زیر " +"تعریف کنیم::" #: ../../tutorial/controlflow.rst:716 msgid "" @@ -1056,10 +1567,18 @@ msgid "" " for kw in keywords:\n" " print(kw, \":\", keywords[kw])" msgstr "" +"def cheeseshop(kind, *arguments, **keywords):\n" +" print(\"-- Do you have any\", kind, \"?\")\n" +" print(\"-- I'm sorry, we're all out of\", kind)\n" +" for arg in arguments:\n" +" print(arg)\n" +" print(\"-\" * 40)\n" +" for kw in keywords:\n" +" print(kw, \":\", keywords[kw])" #: ../../tutorial/controlflow.rst:725 msgid "It could be called like this::" -msgstr "" +msgstr "میتواند اینگونه فراخوانده شود::" #: ../../tutorial/controlflow.rst:727 msgid "" @@ -1069,10 +1588,15 @@ msgid "" " client=\"John Cleese\",\n" " sketch=\"Cheese Shop Sketch\")" msgstr "" +"cheeseshop(\"Limburger\", \"It's very runny, sir.\",\n" +" \"It's really very, VERY runny, sir.\",\n" +" shopkeeper=\"Michael Palin\",\n" +" client=\"John Cleese\",\n" +" sketch=\"Cheese Shop Sketch\")" #: ../../tutorial/controlflow.rst:733 msgid "and of course it would print:" -msgstr "" +msgstr "و قطعا این دستور چاپ خواهد کرد:" #: ../../tutorial/controlflow.rst:735 msgid "" @@ -1085,16 +1609,26 @@ msgid "" "client : John Cleese\n" "sketch : Cheese Shop Sketch" msgstr "" +"-- Do you have any Limburger ?\n" +"-- I'm sorry, we're all out of Limburger\n" +"It's very runny, sir.\n" +"It's really very, VERY runny, sir.\n" +"----------------------------------------\n" +"shopkeeper : Michael Palin\n" +"client : John Cleese\n" +"sketch : Cheese Shop Sketch" #: ../../tutorial/controlflow.rst:746 msgid "" "Note that the order in which the keyword arguments are printed is guaranteed " "to match the order in which they were provided in the function call." msgstr "" +"توجه داشته باشید که ترتیب چاپ آرگومان‌های کلیدی تضمین شده است که با ترتیبی که " +"در فراخوانی تابع ارائه شده‌اند مطابقت داشته باشد." #: ../../tutorial/controlflow.rst:750 msgid "Special parameters" -msgstr "" +msgstr "پارامترهای ویژه" #: ../../tutorial/controlflow.rst:752 msgid "" @@ -1104,10 +1638,15 @@ msgid "" "at the function definition to determine if items are passed by position, by " "position or keyword, or by keyword." msgstr "" +"به طور پیش‌فرض، آرگومان‌ها را می‌توان در یک تابع پایتون یا با استفاده از موقعیت " +"یا به‌صورت صریح با کلیدواژه ارسال کرد. برای خوانایی و کارایی، منطقی است که " +"نحوه ارسال آرگومان‌ها را محدود کنیم تا یک توسعه‌دهنده تنها با نگاه کردن به " +"تعریف تابع بتواند تعیین کند که موارد با موقعیت، با موقعیت یا کلیدواژه، یا " +"فقط با کلیدواژه ارسال می‌شوند." #: ../../tutorial/controlflow.rst:758 msgid "A function definition may look like:" -msgstr "" +msgstr "تعریف یک تابع ممکن است به شکل زیر باشد:" #: ../../tutorial/controlflow.rst:760 msgid "" @@ -1118,6 +1657,12 @@ msgid "" " | - Keyword only\n" " -- Positional only" msgstr "" +"def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):\n" +" ----------- ---------- ----------\n" +" | | |\n" +" | Positional or keyword |\n" +" | - Keyword only\n" +" -- Positional only" #: ../../tutorial/controlflow.rst:769 msgid "" @@ -1126,20 +1671,26 @@ msgid "" "only, positional-or-keyword, and keyword-only. Keyword parameters are also " "referred to as named parameters." msgstr "" +"که در آن ``/`` و ``*`` اختیاری هستند. اگر استفاده شوند، این نمادها نوع " +"پارامتر را بر اساس نحوه ارسال آرگومان‌ها به تابع مشخص می‌کنند: فقط موقعیتی، " +"موقعیتی یا کلیدواژه‌ای، و فقط کلیدواژه‌ای. پارامترهای کلیدواژه‌ای همچنین به " +"عنوان پارامترهای نام‌دار شناخته می‌شوند." #: ../../tutorial/controlflow.rst:776 msgid "Positional-or-Keyword Arguments" -msgstr "" +msgstr "آرگومان‌های موقعیتی یا کلیدواژه‌ای" #: ../../tutorial/controlflow.rst:778 msgid "" "If ``/`` and ``*`` are not present in the function definition, arguments may " "be passed to a function by position or by keyword." msgstr "" +"اگر ``/`` و ``*`` در تعریف تابع وجود نداشته باشند، آرگومان‌ها را می‌توان با " +"موقعیت یا با کلیدواژه به یک تابع ارسال کرد." #: ../../tutorial/controlflow.rst:783 msgid "Positional-Only Parameters" -msgstr "" +msgstr "پارامترهای فقط موقعیتی" #: ../../tutorial/controlflow.rst:785 msgid "" @@ -1151,16 +1702,24 @@ msgid "" "parameters. If there is no ``/`` in the function definition, there are no " "positional-only parameters." msgstr "" +"با بررسی دقیق‌تر، می‌توان برخی پارامترها را به صورت *فقط موقعیتی* مشخص کرد. " +"اگر *فقط موقعیتی* باشند، ترتیب پارامترها اهمیت دارد و پارامترها نمی‌توانند با " +"کلیدواژه ارسال شوند. پارامترهای فقط موقعیتی قبل از یک ``/`` (خط مورب) قرار " +"می‌گیرند. ``/`` برای جدا کردن منطقی پارامترهای فقط موقعیتی از سایر پارامترها " +"استفاده می‌شود. اگر ``/`` در تعریف تابع وجود نداشته باشد، هیچ پارامتر فقط " +"موقعیتی وجود ندارد." #: ../../tutorial/controlflow.rst:793 msgid "" "Parameters following the ``/`` may be *positional-or-keyword* or *keyword-" "only*." msgstr "" +"پارامترهای پس از ``/`` می‌توانند *موقعیتی یا کلیدواژه‌ای* یا *فقط کلیدواژه‌ای* " +"باشند." #: ../../tutorial/controlflow.rst:797 msgid "Keyword-Only Arguments" -msgstr "" +msgstr "آرگومان‌های فقط کلیدواژه‌ای" #: ../../tutorial/controlflow.rst:799 msgid "" @@ -1168,16 +1727,21 @@ msgid "" "passed by keyword argument, place an ``*`` in the arguments list just before " "the first *keyword-only* parameter." msgstr "" +"برای مشخص کردن پارامترها به عنوان *فقط کلیدواژه‌ای*، که نشان می‌دهد پارامترها " +"باید با آرگومان کلیدواژه‌ای ارسال شوند، یک ``*`` را در فهرست آرگومان‌ها درست " +"قبل از اولین پارامتر *فقط کلیدواژه‌ای* قرار دهید." #: ../../tutorial/controlflow.rst:805 msgid "Function Examples" -msgstr "" +msgstr "مثال‌های توابع" #: ../../tutorial/controlflow.rst:807 msgid "" "Consider the following example function definitions paying close attention " "to the markers ``/`` and ``*``::" msgstr "" +"تعریف‌های تابع زیر را با دقت بررسی کنید و به نشانه‌های ``/`` و ``*`` توجه " +"کنید::" #: ../../tutorial/controlflow.rst:810 msgid "" @@ -1193,6 +1757,17 @@ msgid "" ">>> def combined_example(pos_only, /, standard, *, kwd_only):\n" "... print(pos_only, standard, kwd_only)" msgstr "" +">>> def standard_arg(arg):\n" +"... print(arg)\n" +"...\n" +">>> def pos_only_arg(arg, /):\n" +"... print(arg)\n" +"...\n" +">>> def kwd_only_arg(*, arg):\n" +"... print(arg)\n" +"...\n" +">>> def combined_example(pos_only, /, standard, *, kwd_only):\n" +"... print(pos_only, standard, kwd_only)" #: ../../tutorial/controlflow.rst:823 msgid "" @@ -1200,6 +1775,9 @@ msgid "" "places no restrictions on the calling convention and arguments may be passed " "by position or keyword::" msgstr "" +"اولین تعریف تابع، یعنی ``standard_arg``، آشناترین شکل است؛ هیچ محدودیتی برای " +"شیوه فراخوانی قرار نمی‌دهد و آرگومان‌ها می‌توانند با موقعیت یا کلیدواژه ارسال " +"شوند::" #: ../../tutorial/controlflow.rst:827 msgid "" @@ -1209,12 +1787,19 @@ msgid "" ">>> standard_arg(arg=2)\n" "2" msgstr "" +">>> standard_arg(2)\n" +"2\n" +"\n" +">>> standard_arg(arg=2)\n" +"2" #: ../../tutorial/controlflow.rst:833 msgid "" "The second function ``pos_only_arg`` is restricted to only use positional " "parameters as there is a ``/`` in the function definition::" msgstr "" +"تابع دوم، ``pos_only_arg``، محدود شده است تا فقط از پارامترهای موقعیتی " +"استفاده کند، زیرا یک ``/`` در تعریف تابع وجود دارد::" #: ../../tutorial/controlflow.rst:836 msgid "" @@ -1227,12 +1812,22 @@ msgid "" "TypeError: pos_only_arg() got some positional-only arguments passed as " "keyword arguments: 'arg'" msgstr "" +">>> pos_only_arg(1)\n" +"1\n" +"\n" +">>> pos_only_arg(arg=1)\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: pos_only_arg() got some positional-only arguments passed as " +"keyword arguments: 'arg'" #: ../../tutorial/controlflow.rst:844 msgid "" "The third function ``kwd_only_arg`` only allows keyword arguments as " "indicated by a ``*`` in the function definition::" msgstr "" +"تابع سوم، ``kwd_only_arg``، همان‌طور که وجود یک ``*`` در تعریف تابع نشان " +"می‌دهد، فقط آرگومان‌های کلیدواژه‌ای را می‌پذیرد::" #: ../../tutorial/controlflow.rst:847 msgid "" @@ -1244,12 +1839,19 @@ msgid "" ">>> kwd_only_arg(arg=3)\n" "3" msgstr "" +">>> kwd_only_arg(3)\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: kwd_only_arg() takes 0 positional arguments but 1 was given\n" +"\n" +">>> kwd_only_arg(arg=3)\n" +"3" #: ../../tutorial/controlflow.rst:855 msgid "" "And the last uses all three calling conventions in the same function " "definition::" -msgstr "" +msgstr "و تابع آخر از هر سه شیوه فراخوانی در یک تعریف تابع استفاده می‌کند::" #: ../../tutorial/controlflow.rst:858 msgid "" @@ -1270,6 +1872,22 @@ msgid "" "TypeError: combined_example() got some positional-only arguments passed as " "keyword arguments: 'pos_only'" msgstr "" +">>> combined_example(1, 2, 3)\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: combined_example() takes 2 positional arguments but 3 were given\n" +"\n" +">>> combined_example(1, 2, kwd_only=3)\n" +"1 2 3\n" +"\n" +">>> combined_example(1, standard=2, kwd_only=3)\n" +"1 2 3\n" +"\n" +">>> combined_example(pos_only=1, standard=2, kwd_only=3)\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: combined_example() got some positional-only arguments passed as " +"keyword arguments: 'pos_only'" #: ../../tutorial/controlflow.rst:875 msgid "" @@ -1277,18 +1895,26 @@ msgid "" "between the positional argument ``name`` and ``**kwds`` which has ``name`` " "as a key::" msgstr "" +"در نهایت، این تعریف تابع را در نظر بگیرید که در آن بین آرگومان موقعیتی " +"``name`` و ``**kwds`` که دارای کلیدی به نام ``name`` است، یک برخورد احتمالی " +"وجود دارد::" #: ../../tutorial/controlflow.rst:877 msgid "" "def foo(name, **kwds):\n" " return 'name' in kwds" msgstr "" +"def foo(name, **kwds):\n" +" return 'name' in kwds" #: ../../tutorial/controlflow.rst:880 msgid "" "There is no possible call that will make it return ``True`` as the keyword " "``'name'`` will always bind to the first parameter. For example::" msgstr "" +"هیچ فراخوانی ممکنی وجود ندارد که باعث شود این تابع مقدار ``True`` را " +"برگرداند، زیرا کلیدواژه ``'name'`` همیشه به اولین پارامتر متصل می‌شود. برای " +"مثال::" #: ../../tutorial/controlflow.rst:883 msgid "" @@ -1298,6 +1924,11 @@ msgid "" "TypeError: foo() got multiple values for argument 'name'\n" ">>>" msgstr "" +">>> foo(1, **{'name': 2})\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: foo() got multiple values for argument 'name'\n" +">>>" #: ../../tutorial/controlflow.rst:889 msgid "" @@ -1305,6 +1936,9 @@ msgid "" "``name`` as a positional argument and ``'name'`` as a key in the keyword " "arguments::" msgstr "" +"اما با استفاده از ``/`` (آرگومان‌های فقط موقعیتی)، این امکان وجود دارد، زیرا " +"اجازه می‌دهد ``name`` به عنوان یک آرگومان موقعیتی و ``'name'`` به عنوان یک " +"کلید در آرگومان‌های کلیدواژه‌ای استفاده شود::" #: ../../tutorial/controlflow.rst:891 msgid "" @@ -1314,30 +1948,38 @@ msgid "" ">>> foo(1, **{'name': 2})\n" "True" msgstr "" +">>> def foo(name, /, **kwds):\n" +"... return 'name' in kwds\n" +"...\n" +">>> foo(1, **{'name': 2})\n" +"True" #: ../../tutorial/controlflow.rst:897 msgid "" "In other words, the names of positional-only parameters can be used in " "``**kwds`` without ambiguity." msgstr "" +"به عبارت دیگر، نام پارامترهای فقط موقعیتی می‌تواند بدون ابهام در ``**kwds`` " +"استفاده شود." #: ../../tutorial/controlflow.rst:902 msgid "Recap" -msgstr "" +msgstr "خلاصه" #: ../../tutorial/controlflow.rst:904 msgid "" "The use case will determine which parameters to use in the function " "definition::" msgstr "" +"مورد استفاده تعیین می‌کند که کدام پارامترها را در تعریف تابع استفاده کنید::" #: ../../tutorial/controlflow.rst:906 msgid "def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):" -msgstr "" +msgstr "def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):" #: ../../tutorial/controlflow.rst:908 msgid "As guidance:" -msgstr "" +msgstr "برای راهنمایی:" #: ../../tutorial/controlflow.rst:910 msgid "" @@ -1347,6 +1989,10 @@ msgid "" "is called or if you need to take some positional parameters and arbitrary " "keywords." msgstr "" +"اگر می‌خواهید نام پارامترها برای کاربر قابل دسترس نباشد، از فقط-موقعیتی " +"استفاده کنید. این زمانی مفید است که نام پارامترها معنای واقعی ندارند، زمانی " +"که می‌خواهید ترتیب آرگومان‌ها هنگام فراخوانی تابع اجباری باشد، یا زمانی که به " +"تعدادی پارامتر موقعیتی و کلیدواژه‌های دلخواه نیاز دارید." #: ../../tutorial/controlflow.rst:915 msgid "" @@ -1354,16 +2000,21 @@ msgid "" "understandable by being explicit with names or you want to prevent users " "relying on the position of the argument being passed." msgstr "" +"زمانی که نام‌ها دارای معنا هستند و تعریف تابع با مشخص کردن صریح نام‌ها قابل " +"فهم‌تر می‌شود، یا زمانی که می‌خواهید کاربران به موقعیت آرگومان‌های ارسال‌شده " +"وابسته نشوند، از فقط کلیدواژه‌ای استفاده کنید." #: ../../tutorial/controlflow.rst:918 msgid "" "For an API, use positional-only to prevent breaking API changes if the " "parameter's name is modified in the future." msgstr "" +"برای یک API، از پارامترهای فقط موقعیتی استفاده کنید تا از شکستن تغییرات API " +"در صورت تغییر نام پارامتر در آینده جلوگیری شود." #: ../../tutorial/controlflow.rst:924 msgid "Arbitrary Argument Lists" -msgstr "" +msgstr "فهرست‌های دلخواه آرگومان‌ها" #: ../../tutorial/controlflow.rst:929 msgid "" @@ -1372,12 +2023,18 @@ msgid "" "wrapped up in a tuple (see :ref:`tut-tuples`). Before the variable number " "of arguments, zero or more normal arguments may occur. ::" msgstr "" +"در نهایت، کم‌کاربردترین گزینه این است که مشخص کنید یک تابع می‌تواند با تعداد " +"دلخواهی از آرگومان‌ها فراخوانی شود. این آرگومان‌ها در یک تاپل بسته‌بندی می‌شوند " +"(به :ref:`tut-tuples` مراجعه کنید). پیش از آرگومان‌های با تعداد متغیر، می‌توان " +"صفر یا چند آرگومان معمولی داشت. ::" #: ../../tutorial/controlflow.rst:934 msgid "" "def write_multiple_items(file, separator, *args):\n" " file.write(separator.join(args))" msgstr "" +"def write_multiple_items(file, separator, *args):\n" +" file.write(separator.join(args))" #: ../../tutorial/controlflow.rst:938 msgid "" @@ -1387,6 +2044,11 @@ msgid "" "``*args`` parameter are 'keyword-only' arguments, meaning that they can only " "be used as keywords rather than positional arguments. ::" msgstr "" +"معمولاً این آرگومان‌های *متغیرتعداد* در انتهای فهرست پارامترهای رسمی قرار " +"می‌گیرند، زیرا تمام آرگومان‌های ورودی باقی‌مانده‌ای که به تابع ارسال می‌شوند را " +"جمع‌آوری می‌کنند. هر پارامتر رسمی که پس از پارامتر ``*args`` قرار گیرد، یک " +"آرگومان «فقط کلیدواژه‌ای» است؛ یعنی فقط می‌تواند به عنوان کلیدواژه استفاده شود " +"و نه به صورت آرگومان موقعیتی. ::" #: ../../tutorial/controlflow.rst:944 msgid "" @@ -1398,10 +2060,17 @@ msgid "" ">>> concat(\"earth\", \"mars\", \"venus\", sep=\".\")\n" "'earth.mars.venus'" msgstr "" +">>> def concat(*args, sep=\"/\"):\n" +"... return sep.join(args)\n" +"...\n" +">>> concat(\"earth\", \"mars\", \"venus\")\n" +"'earth/mars/venus'\n" +">>> concat(\"earth\", \"mars\", \"venus\", sep=\".\")\n" +"'earth.mars.venus'" #: ../../tutorial/controlflow.rst:955 msgid "Unpacking Argument Lists" -msgstr "" +msgstr "باز کردن بسته آرگومان‌ها" #: ../../tutorial/controlflow.rst:957 msgid "" @@ -1412,6 +2081,12 @@ msgid "" "separately, write the function call with the ``*``\\ -operator to unpack " "the arguments out of a list or tuple::" msgstr "" +"حالت معکوس زمانی رخ می‌دهد که آرگومان‌ها از قبل در یک فهرست یا تاپل قرار " +"دارند، اما برای فراخوانی تابعی که به آرگومان‌های موقعیتی جداگانه نیاز دارد، " +"باید باز شوند. برای مثال، تابع داخلی :func:`range` آرگومان‌های جداگانه " +"*start* و *stop* را انتظار دارد. اگر این آرگومان‌ها به صورت جداگانه در دسترس " +"نیستند، فراخوانی تابع را با عملگر ``*`` برای باز کردن آرگومان‌ها از یک فهرست " +"یا تاپل بنویسید::" #: ../../tutorial/controlflow.rst:964 msgid "" @@ -1422,12 +2097,20 @@ msgid "" "list\n" "[3, 4, 5]" msgstr "" +">>> list(range(3, 6)) # فراخوانی معمولی با آرگومان‌های جداگانه\n" +"[3, 4, 5]\n" +">>> args = [3, 6]\n" +">>> list(range(*args)) # فراخوانی با آرگومان‌های بازشده از یک " +"فهرست\n" +"[3, 4, 5]" #: ../../tutorial/controlflow.rst:973 msgid "" "In the same fashion, dictionaries can deliver keyword arguments with the " "``**``\\ -operator::" msgstr "" +"به همین شکل، دیکشنری‌ها می‌توانند با عملگر ``**`` آرگومان‌های کلیدواژه‌ای فراهم " +"کنند::" #: ../../tutorial/controlflow.rst:976 msgid "" @@ -1442,10 +2125,20 @@ msgid "" "-- This parrot wouldn't VOOM if you put four million volts through it. E's " "bleedin' demised !" msgstr "" +">>> def parrot(voltage, state='a stiff', action='voom'):\n" +"... print(\"-- This parrot wouldn't\", action, end=' ')\n" +"... print(\"if you put\", voltage, \"volts through it.\", end=' ')\n" +"... print(\"E's\", state, \"!\")\n" +"...\n" +">>> d = {\"voltage\": \"four million\", \"state\": \"bleedin' demised\", " +"\"action\": \"VOOM\"}\n" +">>> parrot(**d)\n" +"-- This parrot wouldn't VOOM if you put four million volts through it. E's " +"bleedin' demised !" #: ../../tutorial/controlflow.rst:989 msgid "Lambda Expressions" -msgstr "" +msgstr "عبارت‌های لامبدا" #: ../../tutorial/controlflow.rst:991 msgid "" @@ -1457,6 +2150,12 @@ msgid "" "definitions, lambda functions can reference variables from the containing " "scope::" msgstr "" +"توابع کوچک بی‌نام را می‌توان با کلیدواژه :keyword:`lambda` ایجاد کرد. این تابع " +"مجموع دو آرگومان خود را برمی‌گرداند: ``lambda a, b: a+b``. توابع لامبدا را " +"می‌توان هر جا که به اشیای تابع نیاز باشد استفاده کرد. آن‌ها از نظر نحوی به یک " +"عبارت منفرد محدود هستند. از نظر معنایی، آن‌ها تنها شکری نحوی برای یک تعریف " +"معمولی تابع هستند. مانند تعریف‌های توابع تو‌در‌تو، توابع لامبدا می‌توانند به " +"متغیرهای حوزهٔ دربرگیرنده دسترسی داشته باشند::" #: ../../tutorial/controlflow.rst:999 msgid "" @@ -1469,6 +2168,14 @@ msgid "" ">>> f(1)\n" "43" msgstr "" +">>> def make_incrementor(n):\n" +"... return lambda x: x + n\n" +"...\n" +">>> f = make_incrementor(42)\n" +">>> f(0)\n" +"42\n" +">>> f(1)\n" +"43" #: ../../tutorial/controlflow.rst:1008 msgid "" @@ -1477,6 +2184,10 @@ msgid "" "instance, :meth:`list.sort` takes a sorting key function *key* which can be " "a lambda function::" msgstr "" +"مثال بالا از یک عبارت لامبدا برای برگرداندن یک تابع استفاده می‌کند. کاربرد " +"دیگر آن، ارسال یک تابع کوچک به عنوان آرگومان است. برای " +"مثال، :meth:`list.sort` یک تابع کلید مرتب‌سازی *key* می‌گیرد که می‌تواند یک " +"تابع لامبدا باشد::" #: ../../tutorial/controlflow.rst:1012 msgid "" @@ -1485,16 +2196,21 @@ msgid "" ">>> pairs\n" "[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]" msgstr "" +">>> pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]\n" +">>> pairs.sort(key=lambda pair: pair[1])\n" +">>> pairs\n" +"[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]" #: ../../tutorial/controlflow.rst:1021 msgid "Documentation Strings" -msgstr "" +msgstr "رشته‌های مستندسازی" #: ../../tutorial/controlflow.rst:1028 msgid "" "Here are some conventions about the content and formatting of documentation " "strings." msgstr "" +"در ادامه، برخی قراردادها دربارهٔ محتوا و قالب‌بندی رشته‌های مستندسازی آمده است." #: ../../tutorial/controlflow.rst:1031 msgid "" @@ -1504,6 +2220,10 @@ msgid "" "to be a verb describing a function's operation). This line should begin " "with a capital letter and end with a period." msgstr "" +"خط اول باید همیشه یک خلاصهٔ کوتاه و مختصر از هدف شیء باشد. برای کوتاه‌تر بودن، " +"نباید به‌طور صریح نام یا نوع شیء را بیان کند، زیرا این موارد از راه‌های دیگری " +"در دسترس هستند (مگر اینکه نام، خود یک فعل باشد که عملکرد یک تابع را توصیف " +"می‌کند). این خط باید با یک حرف بزرگ شروع شود و با نقطه پایان یابد." #: ../../tutorial/controlflow.rst:1037 msgid "" @@ -1512,16 +2232,22 @@ msgid "" "The following lines should be one or more paragraphs describing the object's " "calling conventions, its side effects, etc." msgstr "" +"اگر خطوط بیشتری در رشتهٔ مستندسازی وجود دارد، خط دوم باید خالی باشد تا به‌صورت " +"بصری خلاصه را از ادامهٔ توضیحات جدا کند. خطوط بعدی باید شامل یک یا چند " +"پاراگراف باشند که قراردادهای فراخوانی شیء، عوارض جانبی آن و موارد مشابه را " +"توضیح می‌دهند." #: ../../tutorial/controlflow.rst:1042 msgid "" "The Python parser strips indentation from multi-line string literals when " "they serve as module, class, or function docstrings." msgstr "" +"تجزیه‌گر پایتون هنگام استفاده از رشته‌های چندخطی به عنوان رشته‌های مستندسازی " +"ماژول، کلاس یا تابع، تورفتگی را از آن‌ها حذف می‌کند." #: ../../tutorial/controlflow.rst:1045 msgid "Here is an example of a multi-line docstring::" -msgstr "" +msgstr "در اینجا یک نمونه از یک رشتهٔ مستندسازی چندخطی آمده است::" #: ../../tutorial/controlflow.rst:1047 msgid "" @@ -1543,10 +2269,27 @@ msgid "" " >>> my_function()\n" " >>>" msgstr "" +">>> def my_function():\n" +"... \"\"\"Do nothing, but document it.\n" +"...\n" +"... No, really, it doesn't do anything:\n" +"...\n" +"... >>> my_function()\n" +"... >>>\n" +"... \"\"\"\n" +"... pass\n" +"...\n" +">>> print(my_function.__doc__)\n" +"Do nothing, but document it.\n" +"\n" +"No, really, it doesn't do anything:\n" +"\n" +" >>> my_function()\n" +" >>>" #: ../../tutorial/controlflow.rst:1069 msgid "Function Annotations" -msgstr "" +msgstr "حاشیه‌نویسی‌های تابع" #: ../../tutorial/controlflow.rst:1077 msgid "" @@ -1554,6 +2297,9 @@ msgid "" "information about the types used by user-defined functions (see :pep:`3107` " "and :pep:`484` for more information)." msgstr "" +":ref:`حاشیه‌نویسی‌های تابع ` فراداده‌های کاملاً اختیاری دربارهٔ نوع‌های " +"استفاده‌شده در توابع تعریف‌شده توسط کاربر هستند (برای اطلاعات بیشتر " +"به :pep:`3107` و :pep:`484` مراجعه کنید)." #: ../../tutorial/controlflow.rst:1081 msgid "" @@ -1567,6 +2313,14 @@ msgid "" "statement. The following example has a required argument, an optional " "argument, and the return value annotated::" msgstr "" +":term:`حاشیه‌نویسی‌ها ` در " +"ویژگی :attr:`~object.__annotations__` تابع، به‌صورت یک فرهنگ‌لغت ذخیره می‌شوند " +"و هیچ تأثیری بر بخش دیگری از تابع ندارند. حاشیه‌نویسی پارامترها با قرار دادن " +"یک دونقطه پس از نام پارامتر و سپس یک عبارت که مقدار حاشیه‌نویسی را ارزیابی " +"می‌کند، تعریف می‌شود. حاشیه‌نویسی مقدار بازگشتی با قرار دادن یک نشانهٔ لفظی ``-" +">`` و سپس یک عبارت، بین فهرست پارامترها و دونقطه‌ای که پایان " +"دستور :keyword:`def` را مشخص می‌کند، تعریف می‌شود. مثال زیر دارای یک آرگومان " +"اجباری، یک آرگومان اختیاری و مقدار بازگشتیِ حاشیه‌نویسی‌شده است::" #: ../../tutorial/controlflow.rst:1090 msgid "" @@ -1581,10 +2335,20 @@ msgid "" "Arguments: spam eggs\n" "'spam and eggs'" msgstr "" +">>> def f(ham: str, eggs: str = 'eggs') -> str:\n" +"... print(\"Annotations:\", f.__annotations__)\n" +"... print(\"Arguments:\", ham, eggs)\n" +"... return ham + ' and ' + eggs\n" +"...\n" +">>> f('spam')\n" +"Annotations: {'ham': , 'return': , 'eggs': }\n" +"Arguments: spam eggs\n" +"'spam and eggs'" #: ../../tutorial/controlflow.rst:1103 msgid "Intermezzo: Coding Style" -msgstr "" +msgstr "میان‌پرده: سبک کدنویسی" #: ../../tutorial/controlflow.rst:1108 msgid "" @@ -1594,6 +2358,11 @@ msgid "" "than others. Making it easy for others to read your code is always a good " "idea, and adopting a nice coding style helps tremendously for that." msgstr "" +"اکنون که قصد دارید بخش‌های طولانی‌تر و پیچیده‌تری از کد پایتون بنویسید، زمان " +"مناسبی است تا دربارهٔ *سبک کدنویسی* صحبت کنیم. بیشتر زبان‌ها را می‌توان به " +"سبک‌های مختلفی نوشت (یا دقیق‌تر، *قالب‌بندی* کرد)؛ برخی از این سبک‌ها خواناتر از " +"دیگران هستند. آسان‌تر کردن خواندن کد برای دیگران همیشه ایدهٔ خوبی است و پیروی " +"از یک سبک کدنویسی مناسب کمک بسیار زیادی به این موضوع می‌کند." #: ../../tutorial/controlflow.rst:1114 msgid "" @@ -1602,10 +2371,14 @@ msgid "" "Python developer should read it at some point; here are the most important " "points extracted for you:" msgstr "" +"برای پایتون، :pep:`8` به‌عنوان راهنمای سبکی مطرح شده است که بیشتر پروژه‌ها از " +"آن پیروی می‌کنند؛ این راهنما سبکی بسیار خوانا و چشم‌نواز را ترویج می‌کند. هر " +"توسعه‌دهندهٔ پایتون باید در مقطعی آن را مطالعه کند؛ در ادامه مهم‌ترین نکات آن " +"را برای شما استخراج کرده‌ایم:" #: ../../tutorial/controlflow.rst:1119 msgid "Use 4-space indentation, and no tabs." -msgstr "" +msgstr "از تورفتگی ۴ فاصله‌ای استفاده کنید و از Tab استفاده نکنید." #: ../../tutorial/controlflow.rst:1121 msgid "" @@ -1613,36 +2386,45 @@ msgid "" "nesting depth) and large indentation (easier to read). Tabs introduce " "confusion, and are best left out." msgstr "" +"۴ فاصله سازشی مناسب بین تورفتگی کم (که امکان تو‌در‌تو شدن بیشتر را فراهم " +"می‌کند) و تورفتگی زیاد (که خواندن را آسان‌تر می‌کند) است. استفاده از Tab باعث " +"سردرگمی می‌شود و بهتر است کنار گذاشته شود." #: ../../tutorial/controlflow.rst:1125 msgid "Wrap lines so that they don't exceed 79 characters." -msgstr "" +msgstr "خطوط را طوری شکسته‌بندی کنید که بیشتر از ۷۹ نویسه نباشند." #: ../../tutorial/controlflow.rst:1127 msgid "" "This helps users with small displays and makes it possible to have several " "code files side-by-side on larger displays." msgstr "" +"این کار به کاربرانی که نمایشگرهای کوچک دارند کمک می‌کند و امکان نمایش چندین " +"فایل کد در کنار یکدیگر را در نمایشگرهای بزرگ‌تر فراهم می‌سازد." #: ../../tutorial/controlflow.rst:1130 msgid "" "Use blank lines to separate functions and classes, and larger blocks of code " "inside functions." msgstr "" +"برای جدا کردن توابع و کلاس‌ها، و همچنین بلوک‌های بزرگ‌تر کد درون توابع، از خطوط " +"خالی استفاده کنید." #: ../../tutorial/controlflow.rst:1133 msgid "When possible, put comments on a line of their own." -msgstr "" +msgstr "در صورت امکان، توضیحات را در یک خط جداگانه قرار دهید." #: ../../tutorial/controlflow.rst:1135 msgid "Use docstrings." -msgstr "" +msgstr "از رشته‌های مستندسازی (docstring) استفاده کنید." #: ../../tutorial/controlflow.rst:1137 msgid "" "Use spaces around operators and after commas, but not directly inside " "bracketing constructs: ``a = f(1, 2) + g(3, 4)``." msgstr "" +"در اطراف عملگرها و پس از ویرگول‌ها فاصله قرار دهید، اما مستقیماً درون سازه‌های " +"محصورکننده فاصله نگذارید: ``a = f(1, 2) + g(3, 4)``." #: ../../tutorial/controlflow.rst:1140 msgid "" @@ -1651,6 +2433,11 @@ msgid "" "functions and methods. Always use ``self`` as the name for the first method " "argument (see :ref:`tut-firstclasses` for more on classes and methods)." msgstr "" +"کلاس‌ها و توابع خود را به‌صورت یکدست نام‌گذاری کنید؛ قرارداد رایج این است که " +"برای کلاس‌ها از ``UpperCamelCase`` و برای توابع و متدها از " +"``lowercase_with_underscores`` استفاده شود. همیشه از ``self`` به‌عنوان نام " +"اولین آرگومان متد استفاده کنید (برای اطلاعات بیشتر دربارهٔ کلاس‌ها و متدها " +"به :ref:`tut-firstclasses` مراجعه کنید)." #: ../../tutorial/controlflow.rst:1145 msgid "" @@ -1658,6 +2445,9 @@ msgid "" "environments. Python's default, UTF-8, or even plain ASCII work best in any " "case." msgstr "" +"اگر قرار است کد شما در محیط‌های بین‌المللی استفاده شود، از کدگذاری‌های پیچیده و " +"خاص استفاده نکنید. کدگذاری پیش‌فرض پایتون، یعنی UTF-8، یا حتی ASCII ساده، در " +"هر صورت بهترین انتخاب‌ها هستند." #: ../../tutorial/controlflow.rst:1149 msgid "" @@ -1665,10 +2455,13 @@ msgid "" "slightest chance people speaking a different language will read or maintain " "the code." msgstr "" +"به همین ترتیب، اگر حتی کوچک‌ترین احتمالی وجود دارد که افرادی با زبان‌های دیگر " +"این کد را بخوانند یا نگهداری کنند، از نویسه‌های غیر ASCII در شناسه‌ها استفاده " +"نکنید." #: ../../tutorial/controlflow.rst:1155 msgid "Footnotes" -msgstr "" +msgstr "پانویس‌ها" #: ../../tutorial/controlflow.rst:1156 msgid "" @@ -1676,71 +2469,74 @@ msgid "" "a mutable object is passed, the caller will see any changes the callee makes " "to it (items inserted into a list)." msgstr "" +"در واقع، *فراخوانی با ارجاع به شیء* توصیف دقیق‌تری خواهد بود؛ زیرا اگر یک شیء " +"تغییرپذیر ارسال شود، فراخواننده هر تغییری را که فراخوانی‌شونده روی آن اعمال " +"کند مشاهده خواهد کرد (مانند مواردی که به یک فهرست، عنصرهایی اضافه می‌شود)." #: ../../tutorial/controlflow.rst:48 msgid "statement" -msgstr "" +msgstr "دستور" #: ../../tutorial/controlflow.rst:48 msgid "for" -msgstr "" +msgstr "for" #: ../../tutorial/controlflow.rst:254 msgid "..." -msgstr "" +msgstr "..." #: ../../tutorial/controlflow.rst:254 msgid "ellipsis literal" -msgstr "" +msgstr "لفظ سه‌نقطه" #: ../../tutorial/controlflow.rst:485 ../../tutorial/controlflow.rst:1023 msgid "documentation strings" -msgstr "" +msgstr "رشته‌های مستندسازی" #: ../../tutorial/controlflow.rst:485 ../../tutorial/controlflow.rst:1023 msgid "docstrings" -msgstr "" +msgstr "رشته‌های مستندسازی (docstring)" #: ../../tutorial/controlflow.rst:485 ../../tutorial/controlflow.rst:1023 msgid "strings, documentation" -msgstr "" +msgstr "رشته‌ها، مستندسازی" #: ../../tutorial/controlflow.rst:926 msgid "* (asterisk)" -msgstr "" +msgstr "* (ستاره)" #: ../../tutorial/controlflow.rst:926 ../../tutorial/controlflow.rst:970 msgid "in function calls" -msgstr "" +msgstr "در فراخوانی‌های توابع" #: ../../tutorial/controlflow.rst:970 msgid "**" -msgstr "" +msgstr "**" #: ../../tutorial/controlflow.rst:1072 msgid "function" -msgstr "" +msgstr "تابع" #: ../../tutorial/controlflow.rst:1072 msgid "annotations" -msgstr "" +msgstr "حاشیه‌نویسی" #: ../../tutorial/controlflow.rst:1072 msgid "->" -msgstr "" +msgstr "->" #: ../../tutorial/controlflow.rst:1072 msgid "function annotations" -msgstr "" +msgstr "حاشیه‌نویسی‌های تابع" #: ../../tutorial/controlflow.rst:1072 msgid ": (colon)" -msgstr "" +msgstr ": (علامت نقل‌وقول)" #: ../../tutorial/controlflow.rst:1106 msgid "coding" -msgstr "" +msgstr "کد زدن" #: ../../tutorial/controlflow.rst:1106 msgid "style" -msgstr "" +msgstr "سبک" diff --git a/tutorial/datastructures.po b/tutorial/datastructures.po index c023256fc..36c279544 100644 --- a/tutorial/datastructures.po +++ b/tutorial/datastructures.po @@ -12,76 +12,93 @@ msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-07-25 12:59+0330\n" -"PO-Revision-Date: 2021-06-28 01:50+0000\n" +"PO-Revision-Date: 2026-08-14 08:49+0330\n" "Last-Translator: Alireza Shabani (Revisto) , 2025\n" -"Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/" -"fa/)\n" +"Language-Team: Persian (https://app.transifex.com/python-doc/teams/5390/fa/)\n" "Language: fa\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Generator: Poedit 3.6\n" #: ../../tutorial/datastructures.rst:5 msgid "Data Structures" -msgstr "" +msgstr "ساختمان داده‌ها" #: ../../tutorial/datastructures.rst:7 msgid "" -"This chapter describes some things you've learned about already in more " -"detail, and adds some new things as well." +"This chapter describes some things you've learned about already in more detail, " +"and adds some new things as well." msgstr "" +"این فصل برخی از مواردی را که تاکنون یاد گرفته‌اید با جزئیات بیشتری توضیح می‌دهد و " +"همچنین چند مورد جدید نیز اضافه می‌کند." #: ../../tutorial/datastructures.rst:13 msgid "More on Lists" -msgstr "" +msgstr "بیشتر درباره‌ی لیست‌ها" #: ../../tutorial/datastructures.rst:15 msgid "" -"The :ref:`list ` data type has some more methods. Here are " -"all of the methods of list objects:" +"The :ref:`list ` data type has some more methods. Here are all of " +"the methods of list objects:" msgstr "" +"نوع دادهٔ :ref:`list ` چند متد دیگر نیز دارد. در اینجا تمام متدهای " +"اشیای list آمده‌اند:" #: ../../tutorial/datastructures.rst:21 msgid "Add an item to the end of the list. Similar to ``a[len(a):] = [x]``." -msgstr "" +msgstr "یک آیتم را به انتهای فهرست اضافه می‌کند. مشابه ``a[len(a):] = [x]`` است." #: ../../tutorial/datastructures.rst:27 msgid "" "Extend the list by appending all the items from the iterable. Similar to " "``a[len(a):] = iterable``." msgstr "" +"فهرست را با افزودن تمام آیتم‌های شیء قابل پیمایش گسترش می‌دهد. مشابه ``a[len(a):] " +"= iterable`` است." #: ../../tutorial/datastructures.rst:34 msgid "" "Insert an item at a given position. The first argument is the index of the " -"element before which to insert, so ``a.insert(0, x)`` inserts at the front " -"of the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``." +"element before which to insert, so ``a.insert(0, x)`` inserts at the front of " +"the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``." msgstr "" +"یک آیتم را در موقعیت مشخصی درج می‌کند. اولین آرگومان، نمایهٔ عنصری است که آیتم " +"باید پیش از آن درج شود؛ بنابراین ``a.insert(0, x)`` آیتم را در ابتدای فهرست درج " +"می‌کند و ``a.insert(len(a), x)`` معادل ``a.append(x)`` است." #: ../../tutorial/datastructures.rst:42 msgid "" -"Remove the first item from the list whose value is equal to *value*. It " -"raises a :exc:`ValueError` if there is no such item." +"Remove the first item from the list whose value is equal to *value*. It raises " +"a :exc:`ValueError` if there is no such item." msgstr "" +"اولین آیتم از فهرست را که مقدار آن برابر با *value* است حذف می‌کند. اگر چنین " +"آیتمی وجود نداشته باشد، یک :exc:`ValueError` ایجاد می‌کند." #: ../../tutorial/datastructures.rst:49 msgid "" -"Remove the item at the given position in the list, and return it. If no " -"index is specified, ``a.pop()`` removes and returns the last item in the " -"list. It raises an :exc:`IndexError` if the list is empty or the index is " -"outside the list range." +"Remove the item at the given position in the list, and return it. If no index " +"is specified, ``a.pop()`` removes and returns the last item in the list. It " +"raises an :exc:`IndexError` if the list is empty or the index is outside the " +"list range." msgstr "" +"آیتم موجود در موقعیت مشخص‌شده از فهرست را حذف می‌کند و آن را برمی‌گرداند. اگر هیچ " +"نمایه‌ای مشخص نشده باشد، ``a.pop()`` آخرین آیتم فهرست را حذف کرده و برمی‌گرداند. " +"اگر فهرست خالی باشد یا نمایه خارج از محدودهٔ فهرست باشد، یک :exc:`IndexError` " +"ایجاد می‌کند." #: ../../tutorial/datastructures.rst:58 msgid "Remove all items from the list. Similar to ``del a[:]``." -msgstr "" +msgstr "تمام آیتم‌های فهرست را حذف می‌کند. مشابه ``del a[:]`` است." #: ../../tutorial/datastructures.rst:64 msgid "" -"Return zero-based index of the first occurrence of *value* in the list. " -"Raises a :exc:`ValueError` if there is no such item." +"Return zero-based index of the first occurrence of *value* in the list. Raises " +"a :exc:`ValueError` if there is no such item." msgstr "" +"نمایهٔ مبتنی بر صفرِ اولین رخداد *value* در فهرست را برمی‌گرداند. اگر چنین آیتمی " +"وجود نداشته باشد، یک :exc:`ValueError` ایجاد می‌کند." #: ../../tutorial/datastructures.rst:67 msgid "" @@ -90,33 +107,38 @@ msgid "" "list. The returned index is computed relative to the beginning of the full " "sequence rather than the *start* argument." msgstr "" +"آرگومان‌های اختیاری *start* و *end* مانند نشانه‌گذاری برش تفسیر می‌شوند و برای " +"محدود کردن جستجو به یک زیر‌دنبالهٔ مشخص از فهرست استفاده می‌شوند. نمایهٔ " +"بازگردانده‌شده نسبت به ابتدای دنبالهٔ کامل محاسبه می‌شود، نه نسبت به آرگومان " +"*start*." #: ../../tutorial/datastructures.rst:76 msgid "Return the number of times *value* appears in the list." -msgstr "" +msgstr "تعداد دفعاتی که *value* در فهرست ظاهر می‌شود را برمی‌گرداند." #: ../../tutorial/datastructures.rst:82 msgid "" "Sort the items of the list in place (the arguments can be used for sort " "customization, see :func:`sorted` for their explanation)." msgstr "" +"آیتم‌های فهرست را در جای خود مرتب می‌کند (آرگومان‌ها می‌توانند برای سفارشی‌سازی " +"مرتب‌سازی استفاده شوند؛ برای توضیح آن‌ها به :func:`sorted` مراجعه کنید)." #: ../../tutorial/datastructures.rst:89 msgid "Reverse the elements of the list in place." -msgstr "" +msgstr "عناصر فهرست را در جای خود معکوس می‌کند." #: ../../tutorial/datastructures.rst:95 msgid "Return a shallow copy of the list. Similar to ``a[:]``." -msgstr "" +msgstr "یک کپی سطحی از فهرست را برمی‌گرداند. مشابه ``a[:]`` است." #: ../../tutorial/datastructures.rst:98 msgid "An example that uses most of the list methods::" -msgstr "" +msgstr "مثالی که از بیشتر متدهای فهرست استفاده می‌کند::" #: ../../tutorial/datastructures.rst:100 msgid "" -">>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', " -"'banana']\n" +">>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']\n" ">>> fruits.count('apple')\n" "2\n" ">>> fruits.count('tangerine')\n" @@ -137,36 +159,70 @@ msgid "" ">>> fruits.pop()\n" "'pear'" msgstr "" +">>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']\n" +">>> fruits.count('apple')\n" +"2\n" +">>> fruits.count('tangerine')\n" +"0\n" +">>> fruits.index('banana')\n" +"3\n" +">>> fruits.index('banana', 4) # Find next banana starting at position 4\n" +"6\n" +">>> fruits.reverse()\n" +">>> fruits\n" +"['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']\n" +">>> fruits.append('grape')\n" +">>> fruits\n" +"['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape']\n" +">>> fruits.sort()\n" +">>> fruits\n" +"['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']\n" +">>> fruits.pop()\n" +"'pear'" #: ../../tutorial/datastructures.rst:121 msgid "" -"You might have noticed that methods like ``insert``, ``remove`` or ``sort`` " -"that only modify the list have no return value printed -- they return the " -"default ``None``. [#]_ This is a design principle for all mutable data " -"structures in Python." +"You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that " +"only modify the list have no return value printed -- they return the default " +"``None``. [#]_ This is a design principle for all mutable data structures in " +"Python." msgstr "" +"ممکن است متوجه شده باشید که متدهایی مانند ``insert``، ``remove`` یا ``sort`` که " +"فقط فهرست را تغییر می‌دهند، هیچ مقدار بازگشتی چاپ‌شده‌ای ندارند -- آن‌ها مقدار " +"پیش‌فرض ``None`` را برمی‌گردانند. [#]_ این یک اصل طراحی برای تمام ساختارهای دادهٔ " +"تغییرپذیر در پایتون است." #: ../../tutorial/datastructures.rst:126 msgid "" -"Another thing you might notice is that not all data can be sorted or " -"compared. For instance, ``[None, 'hello', 10]`` doesn't sort because " -"integers can't be compared to strings and ``None`` can't be compared to " -"other types. Also, there are some types that don't have a defined ordering " -"relation. For example, ``3+4j < 5+7j`` isn't a valid comparison." +"Another thing you might notice is that not all data can be sorted or compared. " +"For instance, ``[None, 'hello', 10]`` doesn't sort because integers can't be " +"compared to strings and ``None`` can't be compared to other types. Also, there " +"are some types that don't have a defined ordering relation. For example, ``3+4j " +"< 5+7j`` isn't a valid comparison." msgstr "" +"چیز دیگری که ممکن است متوجه شوید این است که همهٔ داده‌ها قابل مرتب‌سازی یا مقایسه " +"نیستند. برای مثال، ``[None, 'hello', 10]`` مرتب نمی‌شود، زیرا اعداد صحیح را " +"نمی‌توان با رشته‌ها مقایسه کرد و ``None`` نیز با نوع‌های دیگر قابل مقایسه نیست. " +"همچنین برخی نوع‌ها وجود دارند که رابطهٔ ترتیب تعریف‌شده‌ای ندارند. برای مثال، مقایسهٔ " +"``3+4j < 5+7j`` معتبر نیست." #: ../../tutorial/datastructures.rst:137 msgid "Using Lists as Stacks" -msgstr "" +msgstr "استفاده از فهرست‌ها به‌عنوان پشته‌ها" #: ../../tutorial/datastructures.rst:142 msgid "" "The list methods make it very easy to use a list as a stack, where the last " -"element added is the first element retrieved (\"last-in, first-out\"). To " -"add an item to the top of the stack, use :meth:`~list.append`. To retrieve " -"an item from the top of the stack, use :meth:`~list.pop` without an explicit " -"index. For example::" +"element added is the first element retrieved (\"last-in, first-out\"). To add " +"an item to the top of the stack, use :meth:`~list.append`. To retrieve an item " +"from the top of the stack, use :meth:`~list.pop` without an explicit index. For " +"example::" msgstr "" +"متدهای فهرست استفاده از یک فهرست به‌عنوان پشته را بسیار آسان می‌کنند؛ جایی که " +"آخرین عنصری که اضافه می‌شود، اولین عنصری است که دریافت می‌شود («آخرین ورودی، اولین " +"خروجی»). برای افزودن یک آیتم به بالای پشته، از :meth:`~list.append` استفاده " +"کنید. برای دریافت یک آیتم از بالای پشته، از :meth:`~list.pop` بدون یک نمایهٔ صریح " +"استفاده کنید. برای مثال::" #: ../../tutorial/datastructures.rst:147 msgid "" @@ -186,25 +242,47 @@ msgid "" ">>> stack\n" "[3, 4]" msgstr "" +">>> stack = [3, 4, 5]\n" +">>> stack.append(6)\n" +">>> stack.append(7)\n" +">>> stack\n" +"[3, 4, 5, 6, 7]\n" +">>> stack.pop()\n" +"7\n" +">>> stack\n" +"[3, 4, 5, 6]\n" +">>> stack.pop()\n" +"6\n" +">>> stack.pop()\n" +"5\n" +">>> stack\n" +"[3, 4]" #: ../../tutorial/datastructures.rst:167 msgid "Using Lists as Queues" -msgstr "" +msgstr "استفاده از لیست‌ها به عنوان صف" #: ../../tutorial/datastructures.rst:171 msgid "" -"It is also possible to use a list as a queue, where the first element added " -"is the first element retrieved (\"first-in, first-out\"); however, lists are " -"not efficient for this purpose. While appends and pops from the end of list " -"are fast, doing inserts or pops from the beginning of a list is slow " -"(because all of the other elements have to be shifted by one)." +"It is also possible to use a list as a queue, where the first element added is " +"the first element retrieved (\"first-in, first-out\"); however, lists are not " +"efficient for this purpose. While appends and pops from the end of list are " +"fast, doing inserts or pops from the beginning of a list is slow (because all of " +"the other elements have to be shifted by one)." msgstr "" +"همچنین می‌توان از یک فهرست به‌عنوان صف استفاده کرد؛ جایی که اولین عنصری که اضافه " +"می‌شود، اولین عنصری است که دریافت می‌شود («اولین ورودی، اولین خروجی»). بااین‌حال، " +"فهرست‌ها برای این منظور کارایی مناسبی ندارند. در حالی که افزودن و حذف از انتهای " +"فهرست سریع است، انجام درج یا حذف از ابتدای فهرست کند است (زیرا تمام عناصر دیگر " +"باید یک موقعیت جابه‌جا شوند)." #: ../../tutorial/datastructures.rst:177 msgid "" -"To implement a queue, use :class:`collections.deque` which was designed to " -"have fast appends and pops from both ends. For example::" +"To implement a queue, use :class:`collections.deque` which was designed to have " +"fast appends and pops from both ends. For example::" msgstr "" +"برای پیاده‌سازی صف، از :class:`collections.deque` استفاده کنید که برای داشتن " +"افزودن و حذف سریع از هر دو انتها طراحی شده است. برای مثال::" #: ../../tutorial/datastructures.rst:180 msgid "" @@ -219,22 +297,36 @@ msgid "" ">>> queue # Remaining queue in order of arrival\n" "deque(['Michael', 'Terry', 'Graham'])" msgstr "" +">>> from collections import deque\n" +">>> queue = deque([\"Eric\", \"John\", \"Michael\"])\n" +">>> queue.append(\"Terry\") # تری از راه میرسد\n" +">>> queue.append(\"Graham\") # گراهام از راه میرسد\n" +">>> queue.popleft() # اولین کسی که آمده حالا میرود\n" +"'Eric'\n" +">>> queue.popleft() # یکی مانده به آخرین کسی که آمده حالا میرود\n" +"'John'\n" +">>> queue # باقی مانده صف به ترتیب آمدن\n" +"deque(['Michael', 'Terry', 'Graham'])" #: ../../tutorial/datastructures.rst:195 msgid "List Comprehensions" -msgstr "" +msgstr "درک‌های فهرستی" #: ../../tutorial/datastructures.rst:197 msgid "" -"List comprehensions provide a concise way to create lists. Common " -"applications are to make new lists where each element is the result of some " -"operations applied to each member of another sequence or iterable, or to " -"create a subsequence of those elements that satisfy a certain condition." +"List comprehensions provide a concise way to create lists. Common applications " +"are to make new lists where each element is the result of some operations " +"applied to each member of another sequence or iterable, or to create a " +"subsequence of those elements that satisfy a certain condition." msgstr "" +"درک‌های فهرستی روشی کوتاه و مختصر برای ایجاد فهرست‌ها فراهم می‌کنند. کاربردهای رایج " +"آن‌ها ایجاد فهرست‌های جدیدی است که در آن‌ها هر عنصر، نتیجهٔ انجام برخی عملیات روی هر " +"عضو از یک دنباله یا شیء قابل پیمایش دیگر است، یا ایجاد یک زیر‌دنباله از عناصری که " +"یک شرط مشخص را برآورده می‌کنند." #: ../../tutorial/datastructures.rst:202 msgid "For example, assume we want to create a list of squares, like::" -msgstr "" +msgstr "برای مثال، فرض کنید می‌خواهیم فهرستی از مربع‌ها ایجاد کنیم، مانند::" #: ../../tutorial/datastructures.rst:204 msgid "" @@ -245,49 +337,65 @@ msgid "" ">>> squares\n" "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]" msgstr "" +">>> squares = []\n" +">>> for x in range(10):\n" +"... squares.append(x**2)\n" +"...\n" +">>> squares\n" +"[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]" #: ../../tutorial/datastructures.rst:211 msgid "" -"Note that this creates (or overwrites) a variable named ``x`` that still " -"exists after the loop completes. We can calculate the list of squares " -"without any side effects using::" +"Note that this creates (or overwrites) a variable named ``x`` that still exists " +"after the loop completes. We can calculate the list of squares without any side " +"effects using::" msgstr "" +"توجه کنید که این کار یک متغیر با نام ``x`` ایجاد می‌کند (یا مقدار آن را بازنویسی " +"می‌کند) که پس از پایان حلقه نیز همچنان وجود دارد. می‌توانیم فهرست مربع‌ها را بدون " +"هیچ اثر جانبی با استفاده از روش زیر محاسبه کنیم::" #: ../../tutorial/datastructures.rst:215 msgid "squares = list(map(lambda x: x**2, range(10)))" -msgstr "" +msgstr "squares = list(map(lambda x: x**2, range(10)))" #: ../../tutorial/datastructures.rst:217 msgid "or, equivalently::" -msgstr "" +msgstr "یا به‌صورت معادل::" #: ../../tutorial/datastructures.rst:219 msgid "squares = [x**2 for x in range(10)]" -msgstr "" +msgstr "squares = [x**2 for x in range(10)]" #: ../../tutorial/datastructures.rst:221 msgid "which is more concise and readable." -msgstr "" +msgstr "که مختصرتر و خواناتر است." #: ../../tutorial/datastructures.rst:223 msgid "" -"A list comprehension consists of brackets containing an expression followed " -"by a :keyword:`!for` clause, then zero or more :keyword:`!for` or :keyword:`!" -"if` clauses. The result will be a new list resulting from evaluating the " -"expression in the context of the :keyword:`!for` and :keyword:`!if` clauses " -"which follow it. For example, this listcomp combines the elements of two " -"lists if they are not equal::" +"A list comprehension consists of brackets containing an expression followed by " +"a :keyword:`!for` clause, then zero or more :keyword:`!for` or :keyword:`!if` " +"clauses. The result will be a new list resulting from evaluating the expression " +"in the context of the :keyword:`!for` and :keyword:`!if` clauses which follow " +"it. For example, this listcomp combines the elements of two lists if they are " +"not equal::" msgstr "" +"یک درک فهرستی شامل کروشه‌هایی است که یک عبارت را در خود دارند و پس از آن یک " +"بند :keyword:`!for` و سپس صفر یا چند بند :keyword:`!for` یا :keyword:`!if` قرار " +"می‌گیرد. نتیجه، یک فهرست جدید خواهد بود که از ارزیابی عبارت در زمینهٔ " +"بندهای :keyword:`!for` و :keyword:`!if` پس از آن به‌دست می‌آید. برای مثال، این درک " +"فهرستی عناصر دو فهرست را در صورتی که برابر نباشند با یکدیگر ترکیب می‌کند::" #: ../../tutorial/datastructures.rst:230 msgid "" ">>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]\n" "[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]" msgstr "" +">>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]\n" +"[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]" #: ../../tutorial/datastructures.rst:233 msgid "and it's equivalent to::" -msgstr "" +msgstr "مساوی است با::" #: ../../tutorial/datastructures.rst:235 msgid "" @@ -300,18 +408,30 @@ msgid "" ">>> combs\n" "[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]" msgstr "" +">>> combs = []\n" +">>> for x in [1,2,3]:\n" +"... for y in [3,1,4]:\n" +"... if x != y:\n" +"... combs.append((x, y))\n" +"...\n" +">>> combs\n" +"[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]" #: ../../tutorial/datastructures.rst:244 msgid "" "Note how the order of the :keyword:`for` and :keyword:`if` statements is the " "same in both these snippets." msgstr "" +"توجه کنید که ترتیب دستورهای :keyword:`for` و :keyword:`if` در هر دو قطعه‌کد یکسان " +"است." #: ../../tutorial/datastructures.rst:247 msgid "" -"If the expression is a tuple (e.g. the ``(x, y)`` in the previous example), " -"it must be parenthesized. ::" +"If the expression is a tuple (e.g. the ``(x, y)`` in the previous example), it " +"must be parenthesized. ::" msgstr "" +"اگر عبارت یک تاپل باشد (برای مثال ``(x, y)`` در مثال قبلی)، باید درون پرانتز " +"قرار گیرد. ::" #: ../../tutorial/datastructures.rst:250 msgid "" @@ -343,11 +463,37 @@ msgid "" ">>> [num for elem in vec for num in elem]\n" "[1, 2, 3, 4, 5, 6, 7, 8, 9]" msgstr "" +">>> vec = [-4, -2, 0, 2, 4]\n" +">>> # ایجاد یک لیست جدید با مقادیر دو برابر شده\n" +">>> [x*2 for x in vec]\n" +"[-8, -4, 0, 4, 8]\n" +">>> # فیلتر کردن لیست برای حذف اعداد منفی\n" +">>> [x for x in vec if x >= 0]\n" +"[0, 2, 4]\n" +">>> # اعمال یک تابع روی تمام عناصر\n" +">>> [abs(x) for x in vec]\n" +"[4, 2, 0, 2, 4]\n" +">>> # فراخوانی یک متد روی هر عنصر\n" +">>> freshfruit = [' banana', ' loganberry ', 'passion fruit ']\n" +">>> [weapon.strip() for weapon in freshfruit]\n" +"['banana', 'loganberry', 'passion fruit']\n" +">>> # ایجاد لیستی از تاپل‌های ۲تایی به شکل (عدد، مربع عدد)\n" +">>> [(x, x**2) for x in range(6)]\n" +"[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]\n" +">>> # تاپل باید داخل پرانتز قرار بگیرد، در غیر این صورت خطا ایجاد می‌شود\n" +">>> [x, x**2 for x in range(6)]\n" +" File \"\", line 1\n" +" [x, x**2 for x in range(6)]\n" +" ^^^^^^^\n" +"SyntaxError: did you forget parentheses around the comprehension target?\n" +">>> # تخت کردن یک لیست با استفاده از listcomp و دو حلقه‌ی for\n" +">>> vec = [[1,2,3], [4,5,6], [7,8,9]]\n" +">>> [num for elem in vec for num in elem]\n" +"[1, 2, 3, 4, 5, 6, 7, 8, 9]" #: ../../tutorial/datastructures.rst:278 -msgid "" -"List comprehensions can contain complex expressions and nested functions::" -msgstr "" +msgid "List comprehensions can contain complex expressions and nested functions::" +msgstr "درک‌های فهرستی می‌توانند شامل عبارت‌های پیچیده و تابع‌های تو‌در‌تو باشند::" #: ../../tutorial/datastructures.rst:280 msgid "" @@ -355,22 +501,29 @@ msgid "" ">>> [str(round(pi, i)) for i in range(1, 6)]\n" "['3.1', '3.14', '3.142', '3.1416', '3.14159']" msgstr "" +">>> from math import pi\n" +">>> [str(round(pi, i)) for i in range(1, 6)]\n" +"['3.1', '3.14', '3.142', '3.1416', '3.14159']" #: ../../tutorial/datastructures.rst:285 msgid "Nested List Comprehensions" -msgstr "" +msgstr "درک‌های فهرستی تو‌در‌تو" #: ../../tutorial/datastructures.rst:287 msgid "" -"The initial expression in a list comprehension can be any arbitrary " -"expression, including another list comprehension." +"The initial expression in a list comprehension can be any arbitrary expression, " +"including another list comprehension." msgstr "" +"عبارت اولیه در یک درک فهرستی می‌تواند هر عبارت دلخواهی باشد، از جمله یک درک " +"فهرستی دیگر." #: ../../tutorial/datastructures.rst:290 msgid "" -"Consider the following example of a 3x4 matrix implemented as a list of 3 " -"lists of length 4::" +"Consider the following example of a 3x4 matrix implemented as a list of 3 lists " +"of length 4::" msgstr "" +"مثال زیر را در نظر بگیرید که یک ماتریس 3x4 را به‌صورت یک فهرست شامل 3 فهرست با " +"طول 4 پیاده‌سازی می‌کند::" #: ../../tutorial/datastructures.rst:293 msgid "" @@ -380,23 +533,32 @@ msgid "" "... [9, 10, 11, 12],\n" "... ]" msgstr "" +">>> matrix = [\n" +"... [1, 2, 3, 4],\n" +"... [5, 6, 7, 8],\n" +"... [9, 10, 11, 12],\n" +"... ]" #: ../../tutorial/datastructures.rst:299 msgid "The following list comprehension will transpose rows and columns::" -msgstr "" +msgstr "درک فهرستی زیر سطرها و ستون‌ها را جابه‌جا می‌کند::" #: ../../tutorial/datastructures.rst:301 msgid "" ">>> [[row[i] for row in matrix] for i in range(4)]\n" "[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" msgstr "" +">>> [[row[i] for row in matrix] for i in range(4)]\n" +"[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" #: ../../tutorial/datastructures.rst:304 msgid "" -"As we saw in the previous section, the inner list comprehension is evaluated " -"in the context of the :keyword:`for` that follows it, so this example is " -"equivalent to::" +"As we saw in the previous section, the inner list comprehension is evaluated in " +"the context of the :keyword:`for` that follows it, so this example is equivalent " +"to::" msgstr "" +"همان‌طور که در بخش قبل دیدیم، درک فهرستی داخلی در زمینهٔ :keyword:`for` که پس از " +"آن قرار گرفته است ارزیابی می‌شود؛ بنابراین این مثال معادل است با::" #: ../../tutorial/datastructures.rst:308 msgid "" @@ -407,10 +569,16 @@ msgid "" ">>> transposed\n" "[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" msgstr "" +">>> transposed = []\n" +">>> for i in range(4):\n" +"... transposed.append([row[i] for row in matrix])\n" +"...\n" +">>> transposed\n" +"[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" #: ../../tutorial/datastructures.rst:315 msgid "which, in turn, is the same as::" -msgstr "" +msgstr "که به نوبهٔ خود، همانند این است::" #: ../../tutorial/datastructures.rst:317 msgid "" @@ -425,37 +593,57 @@ msgid "" ">>> transposed\n" "[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" msgstr "" +">>> transposed = []\n" +">>> for i in range(4):\n" +"... # سه خط بعدی، پیاده‌سازی list comprehension تو در تو را انجام می‌دهند\n" +"... transposed_row = []\n" +"... for row in matrix:\n" +"... transposed_row.append(row[i])\n" +"... transposed.append(transposed_row)\n" +"...\n" +">>> transposed\n" +"[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" #: ../../tutorial/datastructures.rst:328 msgid "" "In the real world, you should prefer built-in functions to complex flow " "statements. The :func:`zip` function would do a great job for this use case::" msgstr "" +"در دنیای واقعی، بهتر است از تابع‌های داخلی به‌جای دستورهای جریان کنترل پیچیده " +"استفاده کنید. تابع :func:`zip` برای این مورد کاربرد بسیار خوبی دارد::" #: ../../tutorial/datastructures.rst:331 msgid "" ">>> list(zip(*matrix))\n" "[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]" msgstr "" +">>> list(zip(*matrix))\n" +"[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]" #: ../../tutorial/datastructures.rst:334 msgid "" "See :ref:`tut-unpacking-arguments` for details on the asterisk in this line." msgstr "" +"برای جزئیات دربارهٔ ستاره در این خط، به :ref:`tut-unpacking-arguments` مراجعه " +"کنید." #: ../../tutorial/datastructures.rst:339 msgid "The :keyword:`!del` statement" -msgstr "" +msgstr "دستور :keyword:`!del`" #: ../../tutorial/datastructures.rst:341 msgid "" "There is a way to remove an item from a list given its index instead of its " -"value: the :keyword:`del` statement. This differs from " -"the :meth:`~list.pop` method which returns a value. The :keyword:`!del` " -"statement can also be used to remove slices from a list or clear the entire " -"list (which we did earlier by assignment of an empty list to the slice). " -"For example::" +"value: the :keyword:`del` statement. This differs from the :meth:`~list.pop` " +"method which returns a value. The :keyword:`!del` statement can also be used to " +"remove slices from a list or clear the entire list (which we did earlier by " +"assignment of an empty list to the slice). For example::" msgstr "" +"روشی برای حذف یک آیتم از فهرست با استفاده از نمایهٔ آن به‌جای مقدار آن وجود دارد: " +"دستور :keyword:`del`. این دستور با متد :meth:`~list.pop` که یک مقدار برمی‌گرداند " +"تفاوت دارد. دستور :keyword:`!del` همچنین می‌تواند برای حذف برش‌هایی از یک فهرست یا " +"خالی کردن کامل فهرست استفاده شود (که پیش‌تر با انتساب یک فهرست خالی به برش انجام " +"دادیم). برای مثال::" #: ../../tutorial/datastructures.rst:347 msgid "" @@ -470,38 +658,55 @@ msgid "" ">>> a\n" "[]" msgstr "" +">>> a = [-1, 1, 66.25, 333, 333, 1234.5]\n" +">>> del a[0]\n" +">>> a\n" +"[1, 66.25, 333, 333, 1234.5]\n" +">>> del a[2:4]\n" +">>> a\n" +"[1, 66.25, 1234.5]\n" +">>> del a[:]\n" +">>> a\n" +"[]" #: ../../tutorial/datastructures.rst:358 msgid ":keyword:`del` can also be used to delete entire variables::" -msgstr "" +msgstr ":keyword:`del` همچنین می‌تواند برای حذف کامل متغیرها استفاده شود::" #: ../../tutorial/datastructures.rst:360 msgid ">>> del a" -msgstr "" +msgstr ">>> del a" #: ../../tutorial/datastructures.rst:362 msgid "" -"Referencing the name ``a`` hereafter is an error (at least until another " -"value is assigned to it). We'll find other uses for :keyword:`del` later." +"Referencing the name ``a`` hereafter is an error (at least until another value " +"is assigned to it). We'll find other uses for :keyword:`del` later." msgstr "" +"ارجاع دادن به نام ``a`` پس از این نقطه یک خطا است (حداقل تا زمانی که مقدار دیگری " +"به آن اختصاص داده شود). بعداً کاربردهای دیگری برای :keyword:`del` خواهیم یافت." #: ../../tutorial/datastructures.rst:369 msgid "Tuples and Sequences" -msgstr "" +msgstr "تاپل‌ها و دنباله‌ها" #: ../../tutorial/datastructures.rst:371 msgid "" -"We saw that lists and strings have many common properties, such as indexing " -"and slicing operations. They are two examples of *sequence* data types " +"We saw that lists and strings have many common properties, such as indexing and " +"slicing operations. They are two examples of *sequence* data types " "(see :ref:`typesseq`). Since Python is an evolving language, other sequence " -"data types may be added. There is also another standard sequence data type: " -"the *tuple*." +"data types may be added. There is also another standard sequence data type: the " +"*tuple*." msgstr "" +"دیدیم که فهرست‌ها و رشته‌ها ویژگی‌های مشترک بسیاری مانند عملیات نمایه‌گذاری و برش " +"دارند. آن‌ها دو نمونه از نوع‌های دادهٔ *دنباله‌ای* (به :ref:`typesseq` مراجعه کنید) " +"هستند. از آنجا که پایتون زبانی در حال تکامل است، ممکن است نوع‌های دادهٔ دنباله‌ای " +"دیگری نیز به آن افزوده شوند. همچنین یک نوع دادهٔ دنباله‌ای استاندارد دیگر وجود " +"دارد: *تاپل*." #: ../../tutorial/datastructures.rst:377 -msgid "" -"A tuple consists of a number of values separated by commas, for instance::" +msgid "A tuple consists of a number of values separated by commas, for instance::" msgstr "" +"یک تاپل از تعدادی مقدار تشکیل شده است که با ویرگول از هم جدا شده‌اند، برای مثال::" #: ../../tutorial/datastructures.rst:379 msgid "" @@ -524,36 +729,70 @@ msgid "" ">>> v\n" "([1, 2, 3], [3, 2, 1])" msgstr "" +">>> t = 12345, 54321, 'hello!'\n" +">>> t[0]\n" +"12345\n" +">>> t\n" +"(12345, 54321, 'hello!')\n" +">>> # تاپل‌ها می‌توانند تو در تو باشند:\n" +">>> u = t, (1, 2, 3, 4, 5)\n" +">>> u\n" +"((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))\n" +">>> # تاپل‌ها تغییرناپذیر هستند:\n" +">>> t[0] = 88888\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"TypeError: 'tuple' object does not support item assignment\n" +">>> # اما می‌توانند شامل اشیای تغییرپذیر باشند:\n" +">>> v = ([1, 2, 3], [3, 2, 1])\n" +">>> v\n" +"([1, 2, 3], [3, 2, 1])" #: ../../tutorial/datastructures.rst:399 msgid "" -"As you see, on output tuples are always enclosed in parentheses, so that " -"nested tuples are interpreted correctly; they may be input with or without " -"surrounding parentheses, although often parentheses are necessary anyway (if " -"the tuple is part of a larger expression). It is not possible to assign to " -"the individual items of a tuple, however it is possible to create tuples " -"which contain mutable objects, such as lists." +"As you see, on output tuples are always enclosed in parentheses, so that nested " +"tuples are interpreted correctly; they may be input with or without surrounding " +"parentheses, although often parentheses are necessary anyway (if the tuple is " +"part of a larger expression). It is not possible to assign to the individual " +"items of a tuple, however it is possible to create tuples which contain mutable " +"objects, such as lists." msgstr "" +"همان‌طور که می‌بینید، در خروجی تاپل‌ها همیشه درون پرانتز قرار می‌گیرند تا تاپل‌های " +"تو‌در‌تو به‌درستی تفسیر شوند؛ آن‌ها می‌توانند با یا بدون پرانتزهای اطرافشان وارد " +"شوند، اگرچه اغلب پرانتزها به هر حال لازم هستند (اگر تاپل بخشی از یک عبارت بزرگ‌تر " +"باشد). امکان انتساب به آیتم‌های جداگانهٔ یک تاپل وجود ندارد، بااین‌حال می‌توان " +"تاپل‌هایی ایجاد کرد که شامل اشیای تغییرپذیر، مانند فهرست‌ها، باشند." #: ../../tutorial/datastructures.rst:406 msgid "" "Though tuples may seem similar to lists, they are often used in different " -"situations and for different purposes. Tuples are :term:`immutable`, and " -"usually contain a heterogeneous sequence of elements that are accessed via " -"unpacking (see later in this section) or indexing (or even by attribute in " -"the case of :func:`namedtuples `). Lists " -"are :term:`mutable`, and their elements are usually homogeneous and are " -"accessed by iterating over the list." -msgstr "" +"situations and for different purposes. Tuples are :term:`immutable`, and usually " +"contain a heterogeneous sequence of elements that are accessed via unpacking " +"(see later in this section) or indexing (or even by attribute in the case " +"of :func:`namedtuples `). Lists are :term:`mutable`, and " +"their elements are usually homogeneous and are accessed by iterating over the " +"list." +msgstr "" +"اگرچه تاپل‌ها ممکن است شبیه فهرست‌ها به نظر برسند، اغلب در موقعیت‌ها و برای اهداف " +"متفاوتی استفاده می‌شوند. تاپل‌ها :term:`immutable` هستند و معمولاً شامل یک دنبالهٔ " +"ناهمگن از عناصر هستند که از طریق بازکردن بسته‌بندی (در ادامهٔ این بخش توضیح داده " +"می‌شود) یا نمایه‌گذاری (یا حتی از طریق ویژگی‌ها در مورد :func:`namedtuples " +"`) به آن‌ها دسترسی پیدا می‌شود. فهرست‌ها :term:`mutable` " +"هستند و عناصر آن‌ها معمولاً همگن هستند و با پیمایش روی فهرست به آن‌ها دسترسی پیدا " +"می‌شود." #: ../../tutorial/datastructures.rst:414 msgid "" "A special problem is the construction of tuples containing 0 or 1 items: the " -"syntax has some extra quirks to accommodate these. Empty tuples are " -"constructed by an empty pair of parentheses; a tuple with one item is " -"constructed by following a value with a comma (it is not sufficient to " -"enclose a single value in parentheses). Ugly, but effective. For example::" +"syntax has some extra quirks to accommodate these. Empty tuples are constructed " +"by an empty pair of parentheses; a tuple with one item is constructed by " +"following a value with a comma (it is not sufficient to enclose a single value " +"in parentheses). Ugly, but effective. For example::" msgstr "" +"یک مسئلهٔ ویژه، ساخت تاپل‌هایی است که شامل 0 یا 1 آیتم هستند: نحو زبان برای " +"سازگاری با این موارد چند نکتهٔ خاص دارد. تاپل‌های خالی با یک جفت پرانتز خالی ساخته " +"می‌شوند؛ یک تاپل با یک آیتم با قرار دادن یک ویرگول پس از یک مقدار ساخته می‌شود " +"(قرار دادن یک مقدار تنها درون پرانتز کافی نیست). زشت، اما مؤثر. برای مثال::" #: ../../tutorial/datastructures.rst:420 msgid "" @@ -566,63 +805,87 @@ msgid "" ">>> singleton\n" "('hello',)" msgstr "" +">>> empty = ()\n" +">>> singleton = 'hello', # <-- به وجود کامای انتهایی توجه کنید\n" +">>> len(empty)\n" +"0\n" +">>> len(singleton)\n" +"1\n" +">>> singleton\n" +"('hello',)" #: ../../tutorial/datastructures.rst:429 msgid "" -"The statement ``t = 12345, 54321, 'hello!'`` is an example of *tuple " -"packing*: the values ``12345``, ``54321`` and ``'hello!'`` are packed " -"together in a tuple. The reverse operation is also possible::" +"The statement ``t = 12345, 54321, 'hello!'`` is an example of *tuple packing*: " +"the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. " +"The reverse operation is also possible::" msgstr "" +"دستور ``t = 12345, 54321, 'hello!'`` نمونه‌ای از *بسته‌بندی تاپل* (*tuple " +"packing*) است: مقدارهای ``12345``، ``54321`` و ``'hello!'`` در یک تاپل بسته‌بندی " +"می‌شوند. عملیات معکوس نیز امکان‌پذیر است::" #: ../../tutorial/datastructures.rst:433 msgid ">>> x, y, z = t" -msgstr "" +msgstr ">>> x, y, z = t" #: ../../tutorial/datastructures.rst:435 msgid "" "This is called, appropriately enough, *sequence unpacking* and works for any " -"sequence on the right-hand side. Sequence unpacking requires that there are " -"as many variables on the left side of the equals sign as there are elements " -"in the sequence. Note that multiple assignment is really just a combination " -"of tuple packing and sequence unpacking." +"sequence on the right-hand side. Sequence unpacking requires that there are as " +"many variables on the left side of the equals sign as there are elements in the " +"sequence. Note that multiple assignment is really just a combination of tuple " +"packing and sequence unpacking." msgstr "" +"این عملیات، به‌درستی، *بازکردن بسته‌بندی دنباله* (*sequence unpacking*) نامیده " +"می‌شود و برای هر دنباله‌ای در سمت راست کار می‌کند. بازکردن بسته‌بندی دنباله نیاز " +"دارد که در سمت چپ علامت مساوی به همان تعداد عناصر موجود در دنباله، متغیر وجود " +"داشته باشد. توجه کنید که انتساب چندگانه در واقع ترکیبی از بسته‌بندی تاپل و " +"بازکردن بسته‌بندی دنباله است." #: ../../tutorial/datastructures.rst:445 msgid "Sets" -msgstr "" +msgstr "مجموعه‌ها" #: ../../tutorial/datastructures.rst:447 msgid "" "Python also includes a data type for :ref:`sets `. A set is an " -"unordered collection with no duplicate elements. Basic uses include " -"membership testing and eliminating duplicate entries. Set objects also " -"support mathematical operations like union, intersection, difference, and " -"symmetric difference." +"unordered collection with no duplicate elements. Basic uses include membership " +"testing and eliminating duplicate entries. Set objects also support " +"mathematical operations like union, intersection, difference, and symmetric " +"difference." msgstr "" +"پایتون همچنین یک نوع داده برای :ref:`set ` دارد. یک مجموعه، مجموعه‌ای " +"نامرتب از عناصر بدون مقدارهای تکراری است. کاربردهای پایهٔ آن شامل بررسی عضویت و " +"حذف ورودی‌های تکراری است. اشیای مجموعه همچنین از عملیات ریاضی مانند اجتماع، " +"اشتراک، تفاضل و تفاضل متقارن پشتیبانی می‌کنند." #: ../../tutorial/datastructures.rst:453 msgid "" -"Curly braces or the :func:`set` function can be used to create sets. Note: " -"to create an empty set you have to use ``set()``, not ``{}``; the latter " -"creates an empty dictionary, a data structure that we discuss in the next " -"section." +"Curly braces or the :func:`set` function can be used to create sets. Note: to " +"create an empty set you have to use ``set()``, not ``{}``; the latter creates an " +"empty dictionary, a data structure that we discuss in the next section." msgstr "" +"از آکولادها یا تابع :func:`set` می‌توان برای ایجاد مجموعه‌ها استفاده کرد. توجه: " +"برای ایجاد یک مجموعهٔ خالی باید از ``set()`` استفاده کنید، نه ``{}``؛ مورد دوم یک " +"فرهنگ لغت خالی ایجاد می‌کند، که یک ساختار داده است و در بخش بعدی دربارهٔ آن صحبت " +"می‌کنیم." #: ../../tutorial/datastructures.rst:457 msgid "" -"Because sets are unordered, iterating over them or printing them can produce " -"the elements in a different order than you expect." +"Because sets are unordered, iterating over them or printing them can produce the " +"elements in a different order than you expect." msgstr "" +"از آنجا که مجموعه‌ها نامرتب هستند، پیمایش روی آن‌ها یا چاپ کردنشان ممکن است عناصر " +"را با ترتیبی متفاوت از چیزی که انتظار دارید تولید کند." #: ../../tutorial/datastructures.rst:460 msgid "Here is a brief demonstration::" -msgstr "" +msgstr "در اینجا یک نمایش کوتاه ارائه شده است::" #: ../../tutorial/datastructures.rst:462 msgid "" ">>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n" -">>> print(basket) # show that duplicates have been " -"removed\n" +">>> print(basket) # show that duplicates have been removed\n" "{'orange', 'banana', 'pear', 'apple'}\n" ">>> 'orange' in basket # fast membership testing\n" "True\n" @@ -644,12 +907,36 @@ msgid "" ">>> a ^ b # letters in a or b but not both\n" "{'r', 'd', 'b', 'm', 'z', 'l'}" msgstr "" +">>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n" +">>> print(basket) # نشان می‌دهد که موارد تکراری حذف شده‌اند\n" +"{'orange', 'banana', 'pear', 'apple'}\n" +">>> 'orange' in basket # بررسی سریع وجود یک عضو\n" +"True\n" +">>> 'crabgrass' in basket\n" +"False\n" +"\n" +">>> # نمایش عملیات مجموعه‌ها روی حروف یکتای دو کلمه\n" +">>>\n" +">>> a = set('abracadabra')\n" +">>> b = set('alacazam')\n" +">>> a # حروف یکتای موجود در a\n" +"{'a', 'r', 'b', 'c', 'd'}\n" +">>> a - b # حروفی که در a هستند اما در b نیستند\n" +"{'r', 'd', 'b'}\n" +">>> a | b # حروفی که در a یا b یا هر دو وجود دارند\n" +"{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}\n" +">>> a & b # حروفی که هم در a و هم در b وجود دارند\n" +"{'a', 'c'}\n" +">>> a ^ b # حروفی که در a یا b هستند اما در هر دو " +"نیستند\n" +"{'r', 'd', 'b', 'm', 'z', 'l'}" #: ../../tutorial/datastructures.rst:485 msgid "" -"Similarly to :ref:`list comprehensions `, set comprehensions " -"are also supported::" +"Similarly to :ref:`list comprehensions `, set comprehensions are " +"also supported::" msgstr "" +"مانند :ref:`درک‌های فهرستی `، درک‌های مجموعه نیز پشتیبانی می‌شوند::" #: ../../tutorial/datastructures.rst:488 msgid "" @@ -657,62 +944,92 @@ msgid "" ">>> a\n" "{'r', 'd'}" msgstr "" +">>> a = {x for x in 'abracadabra' if x not in 'abc'}\n" +">>> a\n" +"{'r', 'd'}" #: ../../tutorial/datastructures.rst:496 msgid "Dictionaries" -msgstr "" +msgstr "فرهنگ‌های لغت" #: ../../tutorial/datastructures.rst:498 msgid "" "Another useful data type built into Python is the *dictionary* " -"(see :ref:`typesmapping`). Dictionaries are sometimes found in other " -"languages as \"associative memories\" or \"associative arrays\". Unlike " -"sequences, which are indexed by a range of numbers, dictionaries are indexed " -"by *keys*, which can be any immutable type; strings and numbers can always " -"be keys. Tuples can be used as keys if they contain only strings, numbers, " -"or tuples; if a tuple contains any mutable object either directly or " -"indirectly, it cannot be used as a key. You can't use lists as keys, since " -"lists can be modified in place using index assignments, slice assignments, " -"or methods like :meth:`~list.append` and :meth:`~list.extend`." -msgstr "" +"(see :ref:`typesmapping`). Dictionaries are sometimes found in other languages " +"as \"associative memories\" or \"associative arrays\". Unlike sequences, which " +"are indexed by a range of numbers, dictionaries are indexed by *keys*, which can " +"be any immutable type; strings and numbers can always be keys. Tuples can be " +"used as keys if they contain only strings, numbers, or tuples; if a tuple " +"contains any mutable object either directly or indirectly, it cannot be used as " +"a key. You can't use lists as keys, since lists can be modified in place using " +"index assignments, slice assignments, or methods like :meth:`~list.append` " +"and :meth:`~list.extend`." +msgstr "" +"یک نوع دادهٔ مفید دیگر که به‌صورت داخلی در پایتون وجود دارد، *فرهنگ لغت* است " +"(به :ref:`typesmapping` مراجعه کنید). فرهنگ‌های لغت در برخی زبان‌های دیگر با نام " +"«حافظه‌های انجمنی» یا «آرایه‌های انجمنی» شناخته می‌شوند. برخلاف دنباله‌ها که با یک " +"بازه از اعداد نمایه‌گذاری می‌شوند، فرهنگ‌های لغت با *کلیدها* نمایه‌گذاری می‌شوند؛ " +"کلیدها می‌توانند هر نوع تغییرناپذیری باشند؛ رشته‌ها و اعداد همیشه می‌توانند کلید " +"باشند. تاپل‌ها نیز می‌توانند به‌عنوان کلید استفاده شوند، اگر فقط شامل رشته‌ها، اعداد " +"یا تاپل‌ها باشند؛ اگر یک تاپل به‌صورت مستقیم یا غیرمستقیم شامل یک شیء تغییرپذیر " +"باشد، نمی‌توان از آن به‌عنوان کلید استفاده کرد. نمی‌توانید از فهرست‌ها به‌عنوان کلید " +"استفاده کنید، زیرا فهرست‌ها را می‌توان با استفاده از انتساب نمایه‌ای، انتساب برش، " +"یا متدهایی مانند :meth:`~list.append` و :meth:`~list.extend` در محل تغییر داد." #: ../../tutorial/datastructures.rst:509 msgid "" "It is best to think of a dictionary as a set of *key: value* pairs, with the " -"requirement that the keys are unique (within one dictionary). A pair of " -"braces creates an empty dictionary: ``{}``. Placing a comma-separated list " -"of key:value pairs within the braces adds initial key:value pairs to the " -"dictionary; this is also the way dictionaries are written on output." +"requirement that the keys are unique (within one dictionary). A pair of braces " +"creates an empty dictionary: ``{}``. Placing a comma-separated list of key:value " +"pairs within the braces adds initial key:value pairs to the dictionary; this is " +"also the way dictionaries are written on output." msgstr "" +"بهترین روش این است که یک فرهنگ لغت را به‌عنوان مجموعه‌ای از جفت‌های *کلید: مقدار* " +"در نظر بگیرید، با این شرط که کلیدها (درون یک فرهنگ لغت) یکتا باشند. یک جفت " +"آکولاد یک فرهنگ لغت خالی ایجاد می‌کند: ``{}``. قرار دادن یک فهرست جداشده با " +"ویرگول از جفت‌های کلید:مقدار درون آکولاد، جفت‌های اولیهٔ کلید:مقدار را به فرهنگ لغت " +"اضافه می‌کند؛ این همان روشی است که فرهنگ‌های لغت در خروجی نوشته می‌شوند." #: ../../tutorial/datastructures.rst:515 msgid "" "The main operations on a dictionary are storing a value with some key and " -"extracting the value given the key. It is also possible to delete a " -"key:value pair with ``del``. If you store using a key that is already in " -"use, the old value associated with that key is forgotten." +"extracting the value given the key. It is also possible to delete a key:value " +"pair with ``del``. If you store using a key that is already in use, the old " +"value associated with that key is forgotten." msgstr "" +"عملیات اصلی روی یک فرهنگ لغت، ذخیره کردن یک مقدار با یک کلید مشخص و استخراج " +"مقدار با استفاده از کلید است. همچنین امکان حذف یک جفت کلید:مقدار با استفاده از " +"``del`` وجود دارد. اگر مقداری را با کلیدی ذخیره کنید که از قبل استفاده شده است، " +"مقدار قدیمی مرتبط با آن کلید فراموش می‌شود." #: ../../tutorial/datastructures.rst:520 msgid "" -"Extracting a value for a non-existent key by subscripting (``d[key]``) " -"raises a :exc:`KeyError`. To avoid getting this error when trying to access " -"a possibly non-existent key, use the :meth:`~dict.get` method instead, which " -"returns ``None`` (or a specified default value) if the key is not in the " -"dictionary." +"Extracting a value for a non-existent key by subscripting (``d[key]``) raises " +"a :exc:`KeyError`. To avoid getting this error when trying to access a possibly " +"non-existent key, use the :meth:`~dict.get` method instead, which returns " +"``None`` (or a specified default value) if the key is not in the dictionary." msgstr "" +"استخراج مقدار برای یک کلید موجود نیست با استفاده از زیرنویس‌گذاری (``d[key]``) " +"یک :exc:`KeyError` ایجاد می‌کند. برای جلوگیری از دریافت این خطا هنگام تلاش برای " +"دسترسی به کلیدی که ممکن است وجود نداشته باشد، از متد :meth:`~dict.get` استفاده " +"کنید؛ این متد در صورتی که کلید در فرهنگ لغت وجود نداشته باشد، ``None`` (یا یک " +"مقدار پیش‌فرض مشخص‌شده) را برمی‌گرداند." #: ../../tutorial/datastructures.rst:525 msgid "" -"Performing ``list(d)`` on a dictionary returns a list of all the keys used " -"in the dictionary, in insertion order (if you want it sorted, just use " -"``sorted(d)`` instead). To check whether a single key is in the dictionary, " -"use the :keyword:`in` keyword." +"Performing ``list(d)`` on a dictionary returns a list of all the keys used in " +"the dictionary, in insertion order (if you want it sorted, just use " +"``sorted(d)`` instead). To check whether a single key is in the dictionary, use " +"the :keyword:`in` keyword." msgstr "" +"اجرای ``list(d)`` روی یک فرهنگ لغت، فهرستی از تمام کلیدهای استفاده‌شده در فرهنگ " +"لغت را با ترتیب درج آن‌ها برمی‌گرداند (اگر می‌خواهید مرتب شده باشد، فقط از " +"``sorted(d)`` استفاده کنید). برای بررسی اینکه یک کلید مشخص در فرهنگ لغت وجود " +"دارد یا نه، از کلمهٔ کلیدی :keyword:`in` استفاده کنید." #: ../../tutorial/datastructures.rst:530 msgid "Here is a small example using a dictionary::" -msgstr "" +msgstr "در اینجا یک مثال کوچک با استفاده از یک فرهنگ لغت آورده شده است::" #: ../../tutorial/datastructures.rst:532 msgid "" @@ -741,52 +1058,90 @@ msgid "" ">>> 'jack' not in tel\n" "False" msgstr "" +">>> tel = {'jack': 4098, 'sape': 4139}\n" +">>> tel['guido'] = 4127\n" +">>> tel\n" +"{'jack': 4098, 'sape': 4139, 'guido': 4127}\n" +">>> tel['jack']\n" +"4098\n" +">>> tel['irv']\n" +"Traceback (most recent call last):\n" +" File \"\", line 1, in \n" +"KeyError: 'irv'\n" +">>> print(tel.get('irv'))\n" +"None\n" +">>> del tel['sape']\n" +">>> tel['irv'] = 4127\n" +">>> tel\n" +"{'jack': 4098, 'guido': 4127, 'irv': 4127}\n" +">>> list(tel)\n" +"['jack', 'guido', 'irv']\n" +">>> sorted(tel)\n" +"['guido', 'irv', 'jack']\n" +">>> 'guido' in tel\n" +"True\n" +">>> 'jack' not in tel\n" +"False" #: ../../tutorial/datastructures.rst:557 msgid "" -"The :func:`dict` constructor builds dictionaries directly from sequences of " -"key-value pairs::" +"The :func:`dict` constructor builds dictionaries directly from sequences of key-" +"value pairs::" msgstr "" +"سازندهٔ :func:`dict` فرهنگ‌های لغت را مستقیماً از دنباله‌هایی از جفت‌های کلید-مقدار " +"ایجاد می‌کند::" #: ../../tutorial/datastructures.rst:560 msgid "" ">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n" "{'sape': 4139, 'guido': 4127, 'jack': 4098}" msgstr "" +">>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])\n" +"{'sape': 4139, 'guido': 4127, 'jack': 4098}" #: ../../tutorial/datastructures.rst:563 msgid "" "In addition, dict comprehensions can be used to create dictionaries from " "arbitrary key and value expressions::" msgstr "" +"علاوه بر این، درک‌های فرهنگ لغت می‌توانند برای ایجاد فرهنگ‌های لغت از عبارت‌های " +"دلخواه کلید و مقدار استفاده شوند::" #: ../../tutorial/datastructures.rst:566 msgid "" ">>> {x: x**2 for x in (2, 4, 6)}\n" "{2: 4, 4: 16, 6: 36}" msgstr "" +">>> {x: x**2 for x in (2, 4, 6)}\n" +"{2: 4, 4: 16, 6: 36}" #: ../../tutorial/datastructures.rst:569 msgid "" -"When the keys are simple strings, it is sometimes easier to specify pairs " -"using keyword arguments::" +"When the keys are simple strings, it is sometimes easier to specify pairs using " +"keyword arguments::" msgstr "" +"هنگامی که کلیدها رشته‌های ساده هستند، گاهی مشخص کردن جفت‌ها با استفاده از " +"آرگومان‌های کلیدی آسان‌تر است::" #: ../../tutorial/datastructures.rst:572 msgid "" ">>> dict(sape=4139, guido=4127, jack=4098)\n" "{'sape': 4139, 'guido': 4127, 'jack': 4098}" msgstr "" +">>> dict(sape=4139, guido=4127, jack=4098)\n" +"{'sape': 4139, 'guido': 4127, 'jack': 4098}" #: ../../tutorial/datastructures.rst:579 msgid "Looping Techniques" -msgstr "" +msgstr "تکنیک‌های حلقه‌زنی" #: ../../tutorial/datastructures.rst:581 msgid "" "When looping through dictionaries, the key and corresponding value can be " "retrieved at the same time using the :meth:`~dict.items` method. ::" msgstr "" +"هنگام پیمایش روی فرهنگ‌های لغت، کلید و مقدار متناظر آن را می‌توان به‌طور هم‌زمان با " +"استفاده از متد :meth:`~dict.items` دریافت کرد. ::" #: ../../tutorial/datastructures.rst:584 msgid "" @@ -797,12 +1152,20 @@ msgid "" "gallahad the pure\n" "robin the brave" msgstr "" +">>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}\n" +">>> for k, v in knights.items():\n" +"... print(k, v)\n" +"...\n" +"gallahad the pure\n" +"robin the brave" #: ../../tutorial/datastructures.rst:591 msgid "" -"When looping through a sequence, the position index and corresponding value " -"can be retrieved at the same time using the :func:`enumerate` function. ::" +"When looping through a sequence, the position index and corresponding value can " +"be retrieved at the same time using the :func:`enumerate` function. ::" msgstr "" +"هنگام پیمایش روی یک دنباله، نمایهٔ موقعیت و مقدار متناظر آن را می‌توان به‌طور " +"هم‌زمان با استفاده از تابع :func:`enumerate` دریافت کرد. ::" #: ../../tutorial/datastructures.rst:594 msgid "" @@ -813,12 +1176,20 @@ msgid "" "1 tac\n" "2 toe" msgstr "" +">>> for i, v in enumerate(['tic', 'tac', 'toe']):\n" +"... print(i, v)\n" +"...\n" +"0 tic\n" +"1 tac\n" +"2 toe" #: ../../tutorial/datastructures.rst:601 msgid "" -"To loop over two or more sequences at the same time, the entries can be " -"paired with the :func:`zip` function. ::" +"To loop over two or more sequences at the same time, the entries can be paired " +"with the :func:`zip` function. ::" msgstr "" +"برای پیمایش روی دو یا چند دنباله به‌طور هم‌زمان، می‌توان ورودی‌های آن‌ها را با " +"استفاده از تابع :func:`zip` جفت کرد. ::" #: ../../tutorial/datastructures.rst:604 msgid "" @@ -831,12 +1202,22 @@ msgid "" "What is your quest? It is the holy grail.\n" "What is your favorite color? It is blue." msgstr "" +">>> questions = ['name', 'quest', 'favorite color']\n" +">>> answers = ['lancelot', 'the holy grail', 'blue']\n" +">>> for q, a in zip(questions, answers):\n" +"... print('What is your {0}? It is {1}.'.format(q, a))\n" +"...\n" +"What is your name? It is lancelot.\n" +"What is your quest? It is the holy grail.\n" +"What is your favorite color? It is blue." #: ../../tutorial/datastructures.rst:613 msgid "" "To loop over a sequence in reverse, first specify the sequence in a forward " "direction and then call the :func:`reversed` function. ::" msgstr "" +"برای پیمایش روی یک دنباله به‌صورت معکوس، ابتدا دنباله را در جهت عادی مشخص کنید و " +"سپس تابع :func:`reversed` را فراخوانی کنید. ::" #: ../../tutorial/datastructures.rst:616 msgid "" @@ -849,12 +1230,22 @@ msgid "" "3\n" "1" msgstr "" +">>> for i in reversed(range(1, 10, 2)):\n" +"... print(i)\n" +"...\n" +"9\n" +"7\n" +"5\n" +"3\n" +"1" #: ../../tutorial/datastructures.rst:625 msgid "" -"To loop over a sequence in sorted order, use the :func:`sorted` function " -"which returns a new sorted list while leaving the source unaltered. ::" +"To loop over a sequence in sorted order, use the :func:`sorted` function which " +"returns a new sorted list while leaving the source unaltered. ::" msgstr "" +"برای پیمایش روی یک دنباله با ترتیب مرتب‌شده، از تابع :func:`sorted` استفاده کنید " +"که یک فهرست مرتب‌شدهٔ جدید برمی‌گرداند، بدون اینکه دنبالهٔ اصلی را تغییر دهد. ::" #: ../../tutorial/datastructures.rst:628 msgid "" @@ -869,14 +1260,26 @@ msgid "" "orange\n" "pear" msgstr "" +">>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']\n" +">>> for i in sorted(basket):\n" +"... print(i)\n" +"...\n" +"apple\n" +"apple\n" +"banana\n" +"orange\n" +"orange\n" +"pear" #: ../../tutorial/datastructures.rst:639 msgid "" "Using :func:`set` on a sequence eliminates duplicate elements. The use " "of :func:`sorted` in combination with :func:`set` over a sequence is an " -"idiomatic way to loop over unique elements of the sequence in sorted " -"order. ::" +"idiomatic way to loop over unique elements of the sequence in sorted order. ::" msgstr "" +"استفاده از :func:`set` روی یک دنباله، عناصر تکراری را حذف می‌کند. استفاده " +"از :func:`sorted` همراه با :func:`set` روی یک دنباله، روشی رایج در پایتون برای " +"پیمایش روی عناصر یکتای دنباله با ترتیب مرتب‌شده است. ::" #: ../../tutorial/datastructures.rst:643 msgid "" @@ -889,12 +1292,22 @@ msgid "" "orange\n" "pear" msgstr "" +">>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']\n" +">>> for f in sorted(set(basket)):\n" +"... print(f)\n" +"...\n" +"apple\n" +"banana\n" +"orange\n" +"pear" #: ../../tutorial/datastructures.rst:652 msgid "" "It is sometimes tempting to change a list while you are looping over it; " "however, it is often simpler and safer to create a new list instead. ::" msgstr "" +"گاهی هنگام پیمایش روی یک فهرست وسوسه می‌شویم که آن را تغییر دهیم؛ بااین‌حال، اغلب " +"ساده‌تر و امن‌تر است که به‌جای آن یک فهرست جدید ایجاد کنیم. ::" #: ../../tutorial/datastructures.rst:655 msgid "" @@ -908,57 +1321,88 @@ msgid "" ">>> filtered_data\n" "[56.2, 51.7, 55.3, 52.5, 47.8]" msgstr "" +">>> import math\n" +">>> raw_data = [56.2, float('NaN'), 51.7, 55.3, 52.5, float('NaN'), 47.8]\n" +">>> filtered_data = []\n" +">>> for value in raw_data:\n" +"... if not math.isnan(value):\n" +"... filtered_data.append(value)\n" +"...\n" +">>> filtered_data\n" +"[56.2, 51.7, 55.3, 52.5, 47.8]" #: ../../tutorial/datastructures.rst:669 msgid "More on Conditions" -msgstr "" +msgstr "اطلاعات بیشتر دربارهٔ شرط‌ها" #: ../../tutorial/datastructures.rst:671 msgid "" "The conditions used in ``while`` and ``if`` statements can contain any " "operators, not just comparisons." msgstr "" +"شرط‌هایی که در دستورهای ``while`` و ``if`` استفاده می‌شوند، می‌توانند شامل هر " +"عملگری باشند، نه فقط عملگرهای مقایسه‌ای." #: ../../tutorial/datastructures.rst:675 msgid "" "The comparison operators ``in`` and ``not in`` are membership tests that " -"determine whether a value is in (or not in) a container. The operators " -"``is`` and ``is not`` compare whether two objects are really the same " -"object. All comparison operators have the same priority, which is lower " -"than that of all numerical operators." +"determine whether a value is in (or not in) a container. The operators ``is`` " +"and ``is not`` compare whether two objects are really the same object. All " +"comparison operators have the same priority, which is lower than that of all " +"numerical operators." msgstr "" +"عملگرهای مقایسه‌ای ``in`` و ``not in`` آزمون‌های عضویت هستند که مشخص می‌کنند آیا یک " +"مقدار درون یک ظرف (یا خارج از آن) قرار دارد یا نه. عملگرهای ``is`` و ``is not`` " +"بررسی می‌کنند که آیا دو شیء واقعاً همان شیء یکسان هستند یا خیر. تمام عملگرهای " +"مقایسه‌ای اولویت یکسانی دارند که از اولویت تمام عملگرهای عددی پایین‌تر است." #: ../../tutorial/datastructures.rst:681 msgid "" -"Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` " -"is less than ``b`` and moreover ``b`` equals ``c``." +"Comparisons can be chained. For example, ``a < b == c`` tests whether ``a`` is " +"less than ``b`` and moreover ``b`` equals ``c``." msgstr "" +"مقایسه‌ها می‌توانند زنجیره‌ای باشند. برای مثال، ``a < b == c`` بررسی می‌کند که آیا " +"``a`` کوچک‌تر از ``b`` است و علاوه بر آن ``b`` با ``c`` برابر است." #: ../../tutorial/datastructures.rst:684 msgid "" -"Comparisons may be combined using the Boolean operators ``and`` and ``or``, " -"and the outcome of a comparison (or of any other Boolean expression) may be " -"negated with ``not``. These have lower priorities than comparison " -"operators; between them, ``not`` has the highest priority and ``or`` the " -"lowest, so that ``A and not B or C`` is equivalent to ``(A and (not B)) or " -"C``. As always, parentheses can be used to express the desired composition." +"Comparisons may be combined using the Boolean operators ``and`` and ``or``, and " +"the outcome of a comparison (or of any other Boolean expression) may be negated " +"with ``not``. These have lower priorities than comparison operators; between " +"them, ``not`` has the highest priority and ``or`` the lowest, so that ``A and " +"not B or C`` is equivalent to ``(A and (not B)) or C``. As always, parentheses " +"can be used to express the desired composition." msgstr "" +"مقایسه‌ها را می‌توان با استفاده از عملگرهای بولی ``and`` و ``or`` ترکیب کرد و " +"نتیجهٔ یک مقایسه (یا هر عبارت بولی دیگر) را می‌توان با ``not`` نقیض کرد. این " +"عملگرها اولویت پایین‌تری نسبت به عملگرهای مقایسه‌ای دارند؛ در میان آن‌ها، ``not`` " +"بالاترین اولویت و ``or`` پایین‌ترین اولویت را دارد، بنابراین ``A and not B or C`` " +"معادل ``(A and (not B)) or C`` است. همانند همیشه، می‌توان از پرانتزها برای بیان " +"ترکیب موردنظر استفاده کرد." #: ../../tutorial/datastructures.rst:691 msgid "" "The Boolean operators ``and`` and ``or`` are so-called *short-circuit* " "operators: their arguments are evaluated from left to right, and evaluation " -"stops as soon as the outcome is determined. For example, if ``A`` and ``C`` " -"are true but ``B`` is false, ``A and B and C`` does not evaluate the " -"expression ``C``. When used as a general value and not as a Boolean, the " -"return value of a short-circuit operator is the last evaluated argument." -msgstr "" +"stops as soon as the outcome is determined. For example, if ``A`` and ``C`` are " +"true but ``B`` is false, ``A and B and C`` does not evaluate the expression " +"``C``. When used as a general value and not as a Boolean, the return value of a " +"short-circuit operator is the last evaluated argument." +msgstr "" +"عملگرهای بولی ``and`` و ``or`` به‌اصطلاح عملگرهای *کوتاه‌مدار* هستند: آرگومان‌های " +"آن‌ها از چپ به راست ارزیابی می‌شوند و ارزیابی به‌محض مشخص شدن نتیجه متوقف می‌شود. " +"برای مثال، اگر ``A`` و ``C`` درست باشند اما ``B`` نادرست باشد، عبارت ``A and B " +"and C`` عبارت ``C`` را ارزیابی نمی‌کند. هنگامی که یک عملگر کوتاه‌مدار به‌عنوان یک " +"مقدار عمومی و نه به‌عنوان یک مقدار بولی استفاده می‌شود، مقدار بازگشتی آن آخرین " +"آرگومان ارزیابی‌شده است." #: ../../tutorial/datastructures.rst:698 msgid "" -"It is possible to assign the result of a comparison or other Boolean " -"expression to a variable. For example, ::" +"It is possible to assign the result of a comparison or other Boolean expression " +"to a variable. For example, ::" msgstr "" +"امکان اختصاص دادن نتیجهٔ یک مقایسه یا عبارت بولی دیگر به یک متغیر وجود دارد. برای " +"مثال، ::" #: ../../tutorial/datastructures.rst:701 msgid "" @@ -967,34 +1411,51 @@ msgid "" ">>> non_null\n" "'Trondheim'" msgstr "" +">>> string1, string2, string3 = '', 'Trondheim', 'Hammer Dance'\n" +">>> non_null = string1 or string2 or string3\n" +">>> non_null\n" +"'Trondheim'" #: ../../tutorial/datastructures.rst:706 msgid "" "Note that in Python, unlike C, assignment inside expressions must be done " -"explicitly with the :ref:`walrus operator ` ``:=``. This avoids a common class of problems encountered " -"in C programs: typing ``=`` in an expression when ``==`` was intended." +"explicitly with the :ref:`walrus operator ` ``:=``. This avoids a common class of problems encountered in C " +"programs: typing ``=`` in an expression when ``==`` was intended." msgstr "" +"توجه کنید که در پایتون، برخلاف C، انتساب درون عبارت‌ها باید به‌صورت صریح با " +"عملگر :ref:`walrus ` ``:=`` " +"انجام شود. این کار از یک دستهٔ رایج از مشکلات موجود در برنامه‌های C جلوگیری می‌کند: " +"نوشتن ``=`` در یک عبارت، در حالی که منظور ``==`` بوده است." #: ../../tutorial/datastructures.rst:716 msgid "Comparing Sequences and Other Types" -msgstr "" +msgstr "مقایسهٔ دنباله‌ها و انواع دیگر" #: ../../tutorial/datastructures.rst:717 msgid "" "Sequence objects typically may be compared to other objects with the same " -"sequence type. The comparison uses *lexicographical* ordering: first the " -"first two items are compared, and if they differ this determines the outcome " -"of the comparison; if they are equal, the next two items are compared, and " -"so on, until either sequence is exhausted. If two items to be compared are " -"themselves sequences of the same type, the lexicographical comparison is " -"carried out recursively. If all items of two sequences compare equal, the " -"sequences are considered equal. If one sequence is an initial sub-sequence " -"of the other, the shorter sequence is the smaller (lesser) one. " -"Lexicographical ordering for strings uses the Unicode code point number to " -"order individual characters. Some examples of comparisons between sequences " -"of the same type::" -msgstr "" +"sequence type. The comparison uses *lexicographical* ordering: first the first " +"two items are compared, and if they differ this determines the outcome of the " +"comparison; if they are equal, the next two items are compared, and so on, until " +"either sequence is exhausted. If two items to be compared are themselves " +"sequences of the same type, the lexicographical comparison is carried out " +"recursively. If all items of two sequences compare equal, the sequences are " +"considered equal. If one sequence is an initial sub-sequence of the other, the " +"shorter sequence is the smaller (lesser) one. Lexicographical ordering for " +"strings uses the Unicode code point number to order individual characters. Some " +"examples of comparisons between sequences of the same type::" +msgstr "" +"اشیای دنباله‌ای معمولاً می‌توانند با اشیای دیگری از همان نوع دنباله مقایسه شوند. " +"مقایسه از ترتیب *لغت‌نامه‌ای* (*lexicographical*) استفاده می‌کند: ابتدا دو آیتم اول " +"با یکدیگر مقایسه می‌شوند و اگر متفاوت باشند، نتیجهٔ مقایسه را تعیین می‌کنند؛ اگر " +"برابر باشند، دو آیتم بعدی مقایسه می‌شوند و این روند ادامه پیدا می‌کند تا زمانی که " +"یکی از دنباله‌ها به پایان برسد. اگر دو آیتمی که باید مقایسه شوند خودشان " +"دنباله‌هایی از همان نوع باشند، مقایسهٔ لغت‌نامه‌ای به‌صورت بازگشتی انجام می‌شود. اگر " +"تمام آیتم‌های دو دنباله برابر مقایسه شوند، دنباله‌ها برابر در نظر گرفته می‌شوند. " +"اگر یکی از دنباله‌ها زیر‌دنبالهٔ ابتدایی دیگری باشد، دنبالهٔ کوتاه‌تر، کوچک‌تر (کمتر) " +"در نظر گرفته می‌شود. ترتیب لغت‌نامه‌ای برای رشته‌ها از شمارهٔ نقطهٔ کد یونیکد برای " +"مرتب‌سازی نویسه‌های منفرد استفاده می‌کند. چند نمونه از مقایسهٔ دنباله‌های هم‌نوع::" #: ../../tutorial/datastructures.rst:729 msgid "" @@ -1006,22 +1467,36 @@ msgid "" "(1, 2, 3) == (1.0, 2.0, 3.0)\n" "(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)" msgstr "" +"(1, 2, 3) < (1, 2, 4)\n" +"[1, 2, 3] < [1, 2, 4]\n" +"'ABC' < 'C' < 'Pascal' < 'Python'\n" +"(1, 2, 3, 4) < (1, 2, 4)\n" +"(1, 2) < (1, 2, -1)\n" +"(1, 2, 3) == (1.0, 2.0, 3.0)\n" +"(1, 2, ('aa', 'ab')) < (1, 2, ('abc', 'a'), 4)" #: ../../tutorial/datastructures.rst:737 msgid "" "Note that comparing objects of different types with ``<`` or ``>`` is legal " "provided that the objects have appropriate comparison methods. For example, " -"mixed numeric types are compared according to their numeric value, so 0 " -"equals 0.0, etc. Otherwise, rather than providing an arbitrary ordering, " -"the interpreter will raise a :exc:`TypeError` exception." +"mixed numeric types are compared according to their numeric value, so 0 equals " +"0.0, etc. Otherwise, rather than providing an arbitrary ordering, the " +"interpreter will raise a :exc:`TypeError` exception." msgstr "" +"توجه کنید که مقایسهٔ اشیای نوع‌های مختلف با ``<`` یا ``>`` در صورتی مجاز است که " +"اشیا متدهای مقایسهٔ مناسب داشته باشند. برای مثال، نوع‌های عددی ترکیبی بر اساس " +"مقدار عددی خود مقایسه می‌شوند، بنابراین 0 با 0.0 برابر است و موارد مشابه. در غیر " +"این صورت، مفسر به‌جای ارائهٔ یک ترتیب دلخواه، یک استثنای :exc:`TypeError` ایجاد " +"می‌کند." #: ../../tutorial/datastructures.rst:745 msgid "Footnotes" -msgstr "" +msgstr "پانویس‌ها" #: ../../tutorial/datastructures.rst:746 msgid "" "Other languages may return the mutated object, which allows method chaining, " "such as ``d->insert(\"a\")->remove(\"b\")->sort();``." msgstr "" +"زبان‌های دیگر ممکن است شیء تغییر‌یافته را برگردانند، که امکان زنجیره‌سازی متدها را " +"فراهم می‌کند، مانند ``d->insert(\"a\")->remove(\"b\")->sort();``."