-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathprogramming.po
More file actions
2658 lines (2152 loc) · 192 KB
/
Copy pathprogramming.po
File metadata and controls
2658 lines (2152 loc) · 192 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Alireza Shabani (Revisto) <[email protected]>, 2025
# Danial Behzadi <[email protected]>, 2025
# Rafael Fontenelle <[email protected]>, 2025
# Sepehr Rasouli <[email protected]>, 2026
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-09-19 20:08+0330\n"
"PO-Revision-Date: 2026-09-14 09:35+0330\n"
"Last-Translator: Sepehr Rasouli <[email protected]>, 2026\n"
"Language-Team: Persian (https://github.com/python/python-docs-fa/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"
msgid "Programming FAQ"
msgstr "پرسشهای متداول دربارهی برنامهنویسی"
msgid "Contents"
msgstr "فهرست"
msgid "General questions"
msgstr "پرسشهای عمومی"
msgid "Is there a source code-level debugger with breakpoints and single-stepping?"
msgstr "آیا یک اشکالزدای سطح کد منبع با نقاط توقف و اجرای گامبهگام وجود دارد؟"
msgid "Yes."
msgstr "بله."
msgid "Several debuggers for Python are described below, and the built-in function :func:`breakpoint` allows you to drop into any of them."
msgstr "چندین اشکالزدا برای پایتون در زیر توضیح داده شدهاند، و تابع توکار :func:`breakpoint` به شما امکان میدهد وارد هر یک از آنها شوید."
msgid "The pdb module is a simple but adequate console-mode debugger for Python. It is part of the standard Python library, and is :mod:`documented in the Library Reference Manual <pdb>`. You can also write your own debugger by using the code for pdb as an example."
msgstr "ماژول pdb یک اشکالزدای ساده اما کافی در حالت کنسول برای پایتون است. این ماژول بخشی از کتابخانه استاندارد پایتون است و :mod:`مستند شده در راهنمای مرجع کتابخانه <pdb>` است. همچنین میتوانید با استفاده از کد pdb بهعنوان مثال، اشکالزدای خودتان را بنویسید."
msgid "The IDLE interactive development environment, which is part of the standard Python distribution (normally available as :mod:`idlelib`), includes a graphical debugger."
msgstr "محیط توسعه تعاملی IDLE، که بخشی از توزیع استاندارد پایتون است (معمولاً بهصورت :mod:`idlelib` در دسترس است)، شامل یک اشکالزدا گرافیکی است."
msgid "PythonWin is a Python IDE that includes a GUI debugger based on pdb. The PythonWin debugger colors breakpoints and has quite a few cool features such as debugging non-PythonWin programs. PythonWin is available as part of `pywin32 <https://github.com/mhammond/pywin32>`_ project and as a part of the `ActivePython <https://www.activestate.com/products/python/>`_ distribution."
msgstr "PythonWin یک محیط توسعه یکپارچه (IDE) برای پایتون است که شامل یک اشکالزدای مبتنی بر pdb با رابط کاربری گرافیکی (GUI) است. اشکالزدای PythonWin نقاط شکست را رنگی نمایش میدهد و قابلیتهای جالب توجه متعددی مانند اشکالزدایی برنامههایی غیر از PythonWin دارد. PythonWin بهعنوان بخشی از پروژهی `pywin32 <https://github.com/mhammond/pywin32>`_ و بهعنوان بخشی از توزیع `ActivePython <https://www.activestate.com/products/python/>`_ در دسترس است."
msgid "`Eric <https://eric-ide.python-projects.org/>`_ is an IDE built on PyQt and the Scintilla editing component."
msgstr "`Eric <https://eric-ide.python-projects.org/>`_ یک IDE است که بر پایه PyQt و کامپوننت ویرایش Scintilla ساخته شده است."
msgid "`trepan3k <https://github.com/rocky/python3-trepan/>`_ is a gdb-like debugger."
msgstr "`trepan3k <https://github.com/rocky/python3-trepan/>`_ یک اشکالزدای شبیه به gdb است."
msgid "`Visual Studio Code <https://code.visualstudio.com/>`_ is an IDE with debugging tools that integrates with version-control software."
msgstr "`Visual Studio Code <https://code.visualstudio.com/>`_ یک محیط توسعه یکپارچه (IDE) با ابزارهای اشکالزدایی است که با نرمافزار کنترل نسخه یکپارچه میشود."
msgid "There are a number of commercial Python IDEs that include graphical debuggers. They include:"
msgstr "تعدادی IDE تجاری پایتون وجود دارند که شامل اشکالزداهای گرافیکی هستند. این موارد شامل:"
msgid "`Wing IDE <https://wingware.com/>`_"
msgstr "`Wing IDE <https://wingware.com/>`_"
msgid "`PyCharm <https://www.jetbrains.com/pycharm/>`_"
msgstr "`PyCharm <https://www.jetbrains.com/pycharm/>`_"
msgid "Are there tools to help find bugs or perform static analysis?"
msgstr "آیا ابزارهایی برای کمک به یافتن خطاها یا انجام تحلیل ایستا وجود دارد؟"
msgid "`Ruff <https://docs.astral.sh/ruff/>`__, `Pylint <https://pylint.readthedocs.io/>`__ and `Pyflakes <https://github.com/PyCQA/pyflakes>`__ do basic checking that will help you catch bugs sooner."
msgstr "`Ruff <https://docs.astral.sh/ruff/>`__، `Pylint <https://pylint.readthedocs.io/>`__ و `Pyflakes <https://github.com/PyCQA/pyflakes>`__ بررسیهای پایهای انجام میدهند که به شما کمک میکند اشکالها را زودتر پیدا کنید."
msgid "Static type checkers such as `mypy <https://mypy-lang.org/>`__, `ty <https://docs.astral.sh/ty/>`__, `Pyrefly <https://pyrefly.org/>`__, and `pytype <https://github.com/google/pytype>`__ can check type hints in Python source code."
msgstr "بررسیکنندههای نوع ایستا مانند `mypy <https://mypy-lang.org/>`__، `ty <https://docs.astral.sh/ty/>`__، `Pyrefly <https://pyrefly.org/>`__ و `pytype <https://github.com/google/pytype>`__ میتوانند راهنماییهای نوع را در کد منبع پایتون بررسی کنند."
msgid "How can I create a stand-alone binary from a Python script?"
msgstr "چگونه میتوانم از یک اسکریپت پایتون یک دودویی مستقل بسازم؟"
msgid "You don't need the ability to compile Python to C code if all you want is a stand-alone program that users can download and run without having to install the Python distribution first. There are a number of tools that determine the set of modules required by a program and bind these modules together with a Python binary to produce a single executable."
msgstr "اگر تمام خواسته شما برنامهای مستقل است که کاربران بتوانند بدون نیاز به نصب توزیع پایتون در ابتدا، آن را دانلود و اجرا کنند، نیازی به قابلیت کامپایل پایتون به کد C ندارید. ابزارهای متعددی وجود دارند که مجموعه ماژولهای مورد نیاز یک برنامه را تعیین میکنند و این ماژولها را به همراه یک دودویی پایتون به هم مقید میکنند تا یک پرونده اجرایی واحد تولید شود."
msgid "One is to use the freeze tool, which is included in the Python source tree as :source:`Tools/freeze`. It converts Python byte code to C arrays; with a C compiler you can embed all your modules into a new program, which is then linked with the standard Python modules."
msgstr "یکی استفاده از ابزار freeze است که در درخت منبع پایتون بهصورت :source:`Tools/freeze` گنجانده شده است. این ابزار بایتکد پایتون را به آرایههای C تبدیل میکند؛ با یک کامپایلر C میتوانید همه ماژولهای خود را در یک برنامه جدید تعبیه کنید، که سپس با ماژولهای استاندارد پایتون پیوند داده میشود."
msgid "It works by scanning your source recursively for import statements (in both forms) and looking for the modules in the standard Python path as well as in the source directory (for built-in modules). It then turns the bytecode for modules written in Python into C code (array initializers that can be turned into code objects using the marshal module) and creates a custom-made config file that only contains those built-in modules which are actually used in the program. It then compiles the generated C code and links it with the rest of the Python interpreter to form a self-contained binary which acts exactly like your script."
msgstr "این ابزار با اسکن بازگشتی کد منبع شما بهدنبال دستورات ایمپورت (در هر دو شکل) و جستوجوی ماژولها در مسیر استاندارد پایتون و همچنین در پوشه منبع (برای ماژولهای توکار) کار میکند. سپس بایتکد ماژولهای نوشتهشده با پایتون را به کد C تبدیل میکند (مقداردهیهای اولیه آرایه که میتوان آنها را با استفاده از ماژول marshal به اشیای کد تبدیل کرد) و یک پرونده پیکربندی سفارشی ایجاد میکند که فقط شامل آن ماژولهای توکاری است که واقعاً در برنامه بهکار رفتهاند. سپس کد C تولیدشده را کامپایل میکند و آن را با بقیه مفسر پایتون پیوند میدهد تا یک دودویی خودکفا تشکیل شود که دقیقاً مانند اسکریپت شما عمل میکند."
msgid "The following packages can help with the creation of console and GUI executables:"
msgstr "بستههای زیر میتوانند به ایجاد پروندههای اجرایی برای کنسول و رابط کاربری گرافیکی (GUI) کمک کنند:"
msgid "`Nuitka <https://nuitka.net/>`_ (Cross-platform)"
msgstr "`Nuitka <https://nuitka.net/>`_ (چندسکویی)"
msgid "`PyInstaller <https://pyinstaller.org/>`_ (Cross-platform)"
msgstr "`PyInstaller <https://pyinstaller.org/>`_ (چندسکویی)"
msgid "`PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (Cross-platform)"
msgstr "`PyOxidizer <https://pyoxidizer.readthedocs.io/en/stable/>`_ (چندسکویی)"
msgid "`cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (Cross-platform)"
msgstr "`cx_Freeze <https://marcelotduarte.github.io/cx_Freeze/>`_ (چندسکویی)"
msgid "`py2app <https://github.com/ronaldoussoren/py2app>`_ (macOS only)"
msgstr "`py2app <https://github.com/ronaldoussoren/py2app>`_ (فقط macOS)"
msgid "`py2exe <https://www.py2exe.org/>`_ (Windows only)"
msgstr "`py2exe <https://www.py2exe.org/>`_ (فقط ویندوز)"
msgid "Are there coding standards or a style guide for Python programs?"
msgstr "آیا برای برنامههای پایتون، استانداردهای کدنویسی یا راهنمای سبکی وجود دارد؟"
msgid "Yes. The coding style required for standard library modules is documented as :pep:`8`."
msgstr "بله. سبک کدنویسی مورد نیاز برای ماژولهای کتابخانه استاندارد، در :pep:`8` مستند شده است."
msgid "Core language"
msgstr "زبان اصلی"
msgid "Why am I getting an UnboundLocalError when the variable has a value?"
msgstr "چرا وقتی متغیر دارای مقدار است، خطای UnboundLocalError دریافت میکنم؟"
msgid "It can be a surprise to get the :exc:`UnboundLocalError` in previously working code when it is modified by adding an assignment statement somewhere in the body of a function."
msgstr "ممکن است در کدی که پیشتر کار میکرد، پس از اصلاح آن با افزودن یک دستور انتساب در جایی از بدنه یک تابع، دریافت :exc:`UnboundLocalError` غافلگیرکننده باشد."
msgid "This code:"
msgstr "این کد:"
msgid "works, but this code:"
msgstr "کار میکند، اما این کد:"
msgid "results in an :exc:`!UnboundLocalError`:"
msgstr "منجر به :exc:`!UnboundLocalError` میشود:"
msgid "This is because when you make an assignment to a variable in a scope, that variable becomes local to that scope and shadows any similarly named variable in the outer scope. Since the last statement in foo assigns a new value to ``x``, the compiler recognizes it as a local variable. Consequently when the earlier ``print(x)`` attempts to print the uninitialized local variable and an error results."
msgstr "این به این دلیل است که وقتی در یک محدوده به یک متغیر انتساب میدهید، آن متغیر برای آن محدوده محلی میشود و هر متغیر همنام در محدوده بیرونی را میپوشاند. از آنجا که آخرین دستور در foo مقدار جدیدی به ``x`` اختصاص میدهد، کامپایلر آن را بهعنوان یک متغیر محلی میشناسد. در نتیجه، وقتی ``print(x)`` قبلی تلاش میکند متغیر محلی مقداردهینشده را چاپ کند، خطایی رخ میدهد."
msgid "In the example above you can access the outer scope variable by declaring it global:"
msgstr "در مثال بالا میتوانید با سراسری اعلام کردن متغیر محدوده بیرونی، به آن دسترسی داشته باشید:"
msgid "This explicit declaration is required in order to remind you that (unlike the superficially analogous situation with class and instance variables) you are actually modifying the value of the variable in the outer scope:"
msgstr "این اعلام صریح لازم است تا به شما یادآوری کند که (برخلاف موقعیت بهظاهر مشابه با متغیرهای کلاس و نمونه) شما در واقع مقدار متغیر را در محدوده بیرونی تغییر میدهید:"
msgid "You can do a similar thing in a nested scope using the :keyword:`nonlocal` keyword:"
msgstr "شما میتوانید کار مشابهی را در یک محدودهی تودرتو با استفاده از کلیدواژه :keyword:`nonlocal` انجام دهید:"
msgid "What are the rules for local and global variables in Python?"
msgstr "قوانین متغیرهای محلی و سراسری در پایتون چیست؟"
msgid "In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a value anywhere within the function's body, it's assumed to be a local unless explicitly declared as global."
msgstr "در پایتون، متغیرهایی که فقط درون یک تابع به آنها ارجاع داده میشوند، بهطور ضمنی سراسری هستند. اگر به متغیری در هر جایی از بدنهی تابع مقداری انتساب داده شود، آن متغیر محلی فرض میشود، مگر اینکه بهصراحت بهعنوان سراسری اعلام شود."
msgid "Though a bit surprising at first, a moment's consideration explains this. On one hand, requiring :keyword:`global` for assigned variables provides a bar against unintended side-effects. On the other hand, if ``global`` was required for all global references, you'd be using ``global`` all the time. You'd have to declare as global every reference to a built-in function or to a component of an imported module. This clutter would defeat the usefulness of the ``global`` declaration for identifying side-effects."
msgstr "هرچند این موضوع در ابتدا کمی تعجبآور است، اما با کمی تأمل قابل توضیح است. از یک سو، الزام به استفاده از :keyword:`global` برای متغیرهایی که به آنها انتساب داده میشود، مانعی در برابر عوارض جانبی ناخواسته ایجاد میکند. از سوی دیگر، اگر ``global`` برای همه ارجاعات سراسری الزامی بود، همواره از ``global`` استفاده میکردید. مجبور بودید هر ارجاع به یک تابع توکار یا به یک کامپوننت از یک ماژول ایمپورتشده را بهعنوان سراسری اعلام کنید. این شلوغی، سودمندی اعلام ``global`` را برای شناسایی عوارض جانبی از بین میبرد."
msgid "Why do lambdas defined in a loop with different values all return the same result?"
msgstr "چرا لامبداهای تعریفشده در یک حلقه با مقادیر مختلف، همگی نتیجهی یکسانی را برمیگردانند؟"
msgid "Assume you use a for loop to define a few different lambdas (or even plain functions), for example::"
msgstr "فرض کنید با استفاده از یک حلقه for، چند لامبدای متفاوت (یا حتی توابع ساده) تعریف میکنید، برای مثال::"
msgid ""
">>> squares = []\n"
">>> for x in range(5):\n"
"... squares.append(lambda: x**2)"
msgstr ""
">>> squares = []\n"
">>> for x in range(5):\n"
"... squares.append(lambda: x**2)"
msgid "This gives you a list that contains 5 lambdas that calculate ``x**2``. You might expect that, when called, they would return, respectively, ``0``, ``1``, ``4``, ``9``, and ``16``. However, when you actually try you will see that they all return ``16``::"
msgstr "این به شما فهرستی شامل ۵ لامبدا میدهد که ``x**2`` را محاسبه میکنند. ممکن است انتظار داشته باشید که آنها هنگام فراخوانی، بهترتیب ``0``، ``1``، ``4``، ``9`` و ``16`` را برگردانند. با این حال، وقتی واقعاً آن را امتحان کنید، خواهید دید که همهی آنها ``16`` را برمیگردانند::"
msgid ""
">>> squares[2]()\n"
"16\n"
">>> squares[4]()\n"
"16"
msgstr ""
">>> squares[2]()\n"
"16\n"
">>> squares[4]()\n"
"16"
msgid "This happens because ``x`` is not local to the lambdas, but is defined in the outer scope, and it is accessed when the lambda is called --- not when it is defined. At the end of the loop, the value of ``x`` is ``4``, so all the functions now return ``4**2``, that is ``16``. You can also verify this by changing the value of ``x`` and see how the results of the lambdas change::"
msgstr "این اتفاق به این دلیل رخ میدهد که ``x`` برای لامبداها محلی نیست، بلکه در محدوده بیرونی تعریف شده است، و دسترسی به آن هنگام فراخوانی لامبدا انجام میشود — نه هنگام تعریف آن. در پایان حلقه، مقدار ``x`` برابر ``4`` است، بنابراین همه توابع اکنون ``4**2`` را برمیگردانند، یعنی ``16``. همچنین میتوانید این موضوع را با تغییر مقدار ``x`` تأیید کنید و ببینید نتایج لامبداها چگونه تغییر میکنند::"
msgid ""
">>> x = 8\n"
">>> squares[2]()\n"
"64"
msgstr ""
">>> x = 8\n"
">>> squares[2]()\n"
"64"
msgid "In order to avoid this, you need to save the values in variables local to the lambdas, so that they don't rely on the value of the global ``x``::"
msgstr "برای اجتناب از این موضوع، باید مقادیر را در متغیرهای محلیِ lambdaها ذخیره کنید، تا آنها به مقدار ``x`` سراسری وابسته نباشند::"
msgid ""
">>> squares = []\n"
">>> for x in range(5):\n"
"... squares.append(lambda n=x: n**2)"
msgstr ""
">>> squares = []\n"
">>> for x in range(5):\n"
"... squares.append(lambda n=x: n**2)"
msgid "Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed when the lambda is defined so that it has the same value that ``x`` had at that point in the loop. This means that the value of ``n`` will be ``0`` in the first lambda, ``1`` in the second, ``2`` in the third, and so on. Therefore each lambda will now return the correct result::"
msgstr "در اینجا، ``n=x`` یک متغیر جدید ``n`` ایجاد میکند که محلی برای لامبدا است و هنگام تعریف لامبدا محاسبه میشود، بهطوری که همان مقداری را دارد که ``x`` در آن نقطه از حلقه داشت. این بدان معناست که مقدار ``n`` در اولین لامبدا ``0``، در دومین لامبدا ``1``، در سومین لامبدا ``2`` و بههمین ترتیب خواهد بود. بنابراین هر لامبدا اکنون نتیجهی صحیح را برمیگرداند::"
msgid ""
">>> squares[2]()\n"
"4\n"
">>> squares[4]()\n"
"16"
msgstr ""
">>> squares[2]()\n"
"4\n"
">>> squares[4]()\n"
"16"
msgid "Note that this behaviour is not peculiar to lambdas, but applies to regular functions too."
msgstr "توجه داشته باشید که این رفتار مختص به لامبداها نیست، بلکه در مورد توابع معمولی نیز صدق میکند."
msgid "How do I share global variables across modules?"
msgstr "چگونه میتوانم متغیرهای سراسری را بین ماژولها به اشتراک بگذارم؟"
msgid "The canonical way to share information across modules within a single program is to create a special module (often called config or cfg). Just import the config module in all modules of your application; the module then becomes available as a global name. Because there is only one instance of each module, any changes made to the module object get reflected everywhere. For example:"
msgstr "روش کانونیکال برای اشتراکگذاری اطلاعات میان ماژولها در یک برنامه واحد، ایجاد یک ماژول خاص (که اغلب config یا cfg نامیده میشود) است. کافی است ماژول config را در همه ماژولهای برنامه خود ایمپورت کنید؛ سپس این ماژول بهعنوان یک نام سراسری در دسترس قرار میگیرد. از آنجا که تنها یک نمونه از هر ماژول وجود دارد، هر تغییری که در شیء ماژول انجام شود، در همهجا بازتاب مییابد. برای مثال:"
msgid "config.py::"
msgstr "config.py::"
msgid "x = 0 # Default value of the 'x' configuration setting"
msgstr "x = 0 # مقدار پیشفرض تنظیم پیکربندی 'x'"
msgid "mod.py::"
msgstr "mod.py::"
msgid ""
"import config\n"
"config.x = 1"
msgstr ""
"import config\n"
"config.x = 1"
msgid "main.py::"
msgstr "main.py::"
msgid ""
"import config\n"
"import mod\n"
"print(config.x)"
msgstr ""
"import config\n"
"import mod\n"
"print(config.x)"
msgid "Note that using a module is also the basis for implementing the singleton design pattern, for the same reason."
msgstr "توجه داشته باشید که استفاده از یک ماژول نیز به همین دلیل، مبنای پیادهسازی الگوی طراحی تکنمونه (singleton) است."
msgid "What are the \"best practices\" for using import in a module?"
msgstr "«بهترین روشها» برای استفاده از ایمپورت در یک ماژول چیست؟"
msgid "In general, don't use ``from modulename import *``. Doing so clutters the importer's namespace, and makes it much harder for linters to detect undefined names."
msgstr "بهطور کلی، از ``from modulename import *`` استفاده نکنید. این کار باعث شلوغ شدن فضای نام ایمپورتکننده میشود و تشخیص نامهای تعریفنشده را برای لینترها (linters) بسیار دشوارتر میکند."
msgid "Import modules at the top of a file. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. Using one import per line makes it easy to add and delete module imports, but using multiple imports per line uses less screen space."
msgstr "ماژولها را در ابتدای پرونده ایمپورت کنید. این کار مشخص میکند که کد شما به چه ماژولهای دیگری نیاز دارد و از تردید در اینکه نام ماژول در محدوده قرار دارد جلوگیری میکند. استفاده از یک ایمپورت در هر خط، افزودن و حذف ایمپورت ماژولها را آسان میکند، اما استفاده از چند ایمپورت در هر خط فضای کمتری از صفحه را اشغال میکند."
msgid "It's good practice if you import modules in the following order:"
msgstr "بهتر است ماژولها را به ترتیب زیر ایمپورت کنید:"
msgid "standard library modules -- such as :mod:`sys`, :mod:`os`, :mod:`argparse`, :mod:`re`"
msgstr "ماژولهای کتابخانهی استاندارد -- مانند :mod:`sys`، :mod:`os`، :mod:`argparse`، :mod:`re`"
msgid "third-party library modules (anything installed in Python's site-packages directory) -- such as :pypi:`dateutil`, :pypi:`requests`, :pypi:`tzdata`"
msgstr "ماژولهای کتابخانهای شخص ثالث (هر چیزی که در پوشه site-packages پایتون نصب شده است) — مانند :pypi:`dateutil`، :pypi:`requests`، :pypi:`tzdata`"
msgid "locally developed modules"
msgstr "ماژولهای توسعهیافته بهصورت محلی"
msgid "It is sometimes necessary to move imports to a function or class to avoid problems with circular imports. Gordon McMillan says:"
msgstr "گاهی لازم است ایمپورتها را به یک تابع یا کلاس منتقل کنید تا از مشکلات ناشی از ایمپورتهای چرخهای اجتناب کنید. گوردون مکمیلان میگوید:"
msgid "Circular imports are fine where both modules use the \"import <module>\" form of import. They fail when the 2nd module wants to grab a name out of the first (\"from module import name\") and the import is at the top level. That's because names in the 1st are not yet available, because the first module is busy importing the 2nd."
msgstr "ایمپورتهای حلقهای در صورتی مشکلی ندارند که هر دو ماژول از شکل «import <module>» برای ایمپورت استفاده کنند. این ایمپورتها زمانی شکست میخورند که ماژول دوم بخواهد نامی را از ماژول اول بگیرد («from module import name») و ایمپورت در سطح بالا باشد. دلیل این امر آن است که نامهای ماژول اول هنوز در دسترس نیستند، زیرا ماژول اول مشغول ایمپورت کردن ماژول دوم است."
msgid "In this case, if the second module is only used in one function, then the import can easily be moved into that function. By the time the import is called, the first module will have finished initializing, and the second module can do its import."
msgstr "در این حالت، اگر ماژول دوم فقط در یک تابع استفاده شود، میتوان ایمپورت را بهراحتی به آن تابع منتقل کرد. تا زمانی که ایمپورت فراخوانی شود، ماژول اول مقداردهی اولیهی خود را به پایان رسانده است و ماژول دوم میتواند ایمپورت خود را انجام دهد."
msgid "It may also be necessary to move imports out of the top level of code if some of the modules are platform-specific. In that case, it may not even be possible to import all of the modules at the top of the file. In this case, importing the correct modules in the corresponding platform-specific code is a good option."
msgstr "ممکن است همچنین لازم باشد ایمپورتها را به بیرون از سطح بالایی کد منتقل کنید، اگر برخی از ماژولها مختص پلتفرم باشند. در آن صورت، حتی ممکن است نتوان تمام ماژولها را در ابتدای پرونده ایمپورت کرد. در این حالت، ایمپورت کردن ماژولهای صحیح در کد مختص پلتفرم متناظر، گزینه خوبی است."
msgid "Only move imports into a local scope, such as inside a function definition, if it's necessary to solve a problem such as avoiding a circular import or are trying to reduce the initialization time of a module. This technique is especially helpful if many of the imports are unnecessary depending on how the program executes. You may also want to move imports into a function if the modules are only ever used in that function. Note that loading a module the first time may be expensive because of the one time initialization of the module, but loading a module multiple times is virtually free, costing only a couple of dictionary lookups. Even if the module name has gone out of scope, the module is probably available in :data:`sys.modules`."
msgstr "فقط در صورتی ایمپورتها را به یک محدوده محلی منتقل کنید، مانند درون تعریف یک تابع، که این کار برای حل مشکلی مانند اجتناب از یک ایمپورت چرخهای (circular import) ضروری باشد یا بخواهید زمان مقداردهی اولیه یک ماژول را کاهش دهید. این تکنیک بهویژه زمانی مفید است که بسیاری از ایمپورتها، بسته به نحوه اجرای برنامه، غیرضروری باشند. همچنین ممکن است بخواهید ایمپورتها را به یک تابع منتقل کنید، اگر ماژولها تنها در همان تابع استفاده شوند. توجه داشته باشید که بارگذاری یک ماژول برای اولین بار ممکن است به دلیل مقداردهی اولیه یکباره ماژول پرهزینه باشد، اما بارگذاری چندباره یک ماژول عملاً رایگان است و تنها هزینه چند جستجوی دیکشنری را دارد. حتی اگر نام ماژول از محدوده خارج شده باشد، آن ماژول احتمالاً در :data:`sys.modules` در دسترس است."
msgid "Why are default values shared between objects?"
msgstr "چرا مقادیر پیشفرض بین شیءها مشترک هستند؟"
msgid "This type of bug commonly bites neophyte programmers. Consider this function::"
msgstr "این نوع اشکال معمولاً برنامهنویسان تازهکار را گرفتار میکند. این تابع را در نظر بگیرید::"
msgid ""
"def foo(mydict={}): # Danger: shared reference to one dict for all calls\n"
" ... compute something ...\n"
" mydict[key] = value\n"
" return mydict"
msgstr ""
"def foo(mydict={}): # Danger: shared reference to one dict for all calls\n"
" ... compute something ...\n"
" mydict[key] = value\n"
" return mydict"
msgid "The first time you call this function, ``mydict`` contains a single item. The second time, ``mydict`` contains two items because when ``foo()`` begins executing, ``mydict`` starts out with an item already in it."
msgstr "بار اول که این تابع را فراخوانی میکنید، ``mydict`` شامل یک آیتم است. بار دوم، ``mydict`` شامل دو آیتم است، زیرا هنگامی که ``foo()`` شروع به اجرا میکند، ``mydict`` از قبل یک آیتم در خود دارد."
msgid "It is often expected that a function call creates new objects for default values. This is not what happens. Default values are created exactly once, when the function is defined. If that object is changed, like the dictionary in this example, subsequent calls to the function will refer to this changed object."
msgstr "اغلب انتظار میرود که یک فراخوانی تابع، اشیای جدیدی برای مقادیر پیشفرض ایجاد کند. این چیزی نیست که رخ میدهد. مقادیر پیشفرض دقیقاً یک بار، هنگامی که تابع تعریف میشود، ایجاد میشوند. اگر آن شیء تغییر کند، مانند دیکشنری در این مثال، فراخوانیهای بعدی تابع به این شیء تغییریافته ارجاع خواهند داد."
msgid "By definition, immutable objects such as numbers, strings, tuples, and ``None``, are safe from change. Changes to mutable objects such as dictionaries, lists, and class instances can lead to confusion."
msgstr "طبق تعریف، اشیاء تغییرناپذیر مانند اعداد، رشتهها، تاپلها و ``None``، از تغییر مصون هستند. تغییرات در اشیاء تغییرپذیر مانند دیکشنریها، فهرستها و نمونههای کلاس میتواند باعث سردرگمی شود."
msgid "Because of this feature, it is good programming practice to not use mutable objects as default values. Instead, use ``None`` as the default value and inside the function, check if the parameter is ``None`` and create a new list/dictionary/whatever if it is. For example, don't write::"
msgstr "به دلیل این ویژگی، تمرین خوب برنامهنویسی این است که از اشیای تغییرپذیر بهعنوان مقادیر پیشفرض استفاده نکنید. در عوض، از ``None`` بهعنوان مقدار پیشفرض استفاده کنید و داخل تابع بررسی کنید که آیا پارامتر ``None`` است یا خیر، و در این صورت یک فهرست/دیکشنری/هرچیز جدید ایجاد کنید. برای مثال، اینگونه ننویسید::"
msgid ""
"def foo(mydict={}):\n"
" ..."
msgstr ""
"def foo(mydict={}):\n"
" ..."
msgid "but::"
msgstr "اما::"
msgid ""
"def foo(mydict=None):\n"
" if mydict is None:\n"
" mydict = {} # create a new dict for local namespace"
msgstr ""
"def foo(mydict=None):\n"
" if mydict is None:\n"
" mydict = {} # create a new dict for local namespace"
msgid "This feature can be useful. When you have a function that's time-consuming to compute, a common technique is to cache the parameters and the resulting value of each call to the function, and return the cached value if the same value is requested again. This is called \"memoizing\", and can be implemented like this::"
msgstr "این قابلیت میتواند مفید باشد. وقتی تابعی دارید که محاسبهی آن زمانبر است، روش رایج این است که پارامترها و مقدار حاصل از هر فراخوانی تابع را در نهانگاه ذخیره کنید و اگر همان مقدار دوباره درخواست شد، مقدار ذخیرهشده در نهانگاه را برگردانید. به این کار «memoizing» میگویند و میتوان آن را اینگونه پیادهسازی کرد::"
msgid ""
"# Callers can only provide two parameters and optionally pass _cache by keyword\n"
"def expensive(arg1, arg2, *, _cache={}):\n"
" if (arg1, arg2) in _cache:\n"
" return _cache[(arg1, arg2)]\n"
"\n"
" # Calculate the value\n"
" result = ... expensive computation ...\n"
" _cache[(arg1, arg2)] = result # Store result in the cache\n"
" return result"
msgstr ""
"# Callers can only provide two parameters and optionally pass _cache by keyword\n"
"def expensive(arg1, arg2, *, _cache={}):\n"
" if (arg1, arg2) in _cache:\n"
" return _cache[(arg1, arg2)]\n"
"\n"
" # Calculate the value\n"
" result = ... expensive computation ...\n"
" _cache[(arg1, arg2)] = result # Store result in the cache\n"
" return result"
msgid "You could use a global variable containing a dictionary instead of the default value; it's a matter of taste."
msgstr "میتوانید بهجای مقدار پیشفرض از یک متغیر سراسری شامل یک دیکشنری استفاده کنید؛ این موضوع سلیقهای است."
msgid "How can I pass optional or keyword parameters from one function to another?"
msgstr "چگونه میتوانم پارامترهای اختیاری یا کلیدواژهای را از یک تابع به تابع دیگر منتقل کنم؟"
msgid "Collect the arguments using the ``*`` and ``**`` specifiers in the function's parameter list; this gives you the positional arguments as a tuple and the keyword arguments as a dictionary. You can then pass these arguments when calling another function by using ``*`` and ``**``::"
msgstr "آرگومانها را با استفاده از مشخصکنندههای ``*`` و ``**`` در فهرست پارامترهای تابع جمعآوری کنید؛ این کار آرگومانهای جایگاهی را بهصورت یک تاپل و آرگومانهای کلیدواژهای را بهصورت یک دیکشنری به شما میدهد. سپس میتوانید این آرگومانها را هنگام فراخوانی تابعی دیگر با استفاده از ``*`` و ``**`` منتقل کنید::"
msgid ""
"def f(x, *args, **kwargs):\n"
" ...\n"
" kwargs['width'] = '14.3c'\n"
" ...\n"
" g(x, *args, **kwargs)"
msgstr ""
"def f(x, *args, **kwargs):\n"
" ...\n"
" kwargs['width'] = '14.3c'\n"
" ...\n"
" g(x, *args, **kwargs)"
msgid "What is the difference between arguments and parameters?"
msgstr "تفاوت آرگومانها و پارامترها چیست؟"
msgid ":term:`Parameters <parameter>` are defined by the names that appear in a function definition, whereas :term:`arguments <argument>` are the values actually passed to a function when calling it. Parameters define what :term:`kind of arguments <parameter>` a function can accept. For example, given the function definition::"
msgstr ":term:`پارامترها <parameter>` با نامهایی که در تعریف تابع ظاهر میشوند تعریف میشوند، در حالی که :term:`آرگومانها <argument>` مقادیری هستند که هنگام فراخوانی تابع واقعاً به تابع ارسال میشوند. پارامترها مشخص میکنند که تابع چه :term:`نوع آرگومانهایی <parameter>` میتواند بپذیرد. برای مثال، با توجه به تعریف تابع::"
msgid ""
"def func(foo, bar=None, **kwargs):\n"
" pass"
msgstr ""
"def func(foo, bar=None, **kwargs):\n"
" pass"
msgid "*foo*, *bar* and *kwargs* are parameters of ``func``. However, when calling ``func``, for example::"
msgstr "*foo*، *bar* و *kwargs* پارامترهای ``func`` هستند. با این حال، هنگام فراخوانی ``func``، برای مثال::"
msgid "func(42, bar=314, extra=somevar)"
msgstr "func(42, bar=314, extra=somevar)"
msgid "the values ``42``, ``314``, and ``somevar`` are arguments."
msgstr "مقادیر ``42``، ``314`` و ``somevar`` آرگومان هستند."
msgid "Why did changing list 'y' also change list 'x'?"
msgstr "چرا تغییر فهرست 'y' باعث تغییر فهرست 'x' نیز شد؟"
msgid "If you wrote code like::"
msgstr "اگر کدی مانند زیر نوشته باشید::"
msgid ""
">>> x = []\n"
">>> y = x\n"
">>> y.append(10)\n"
">>> y\n"
"[10]\n"
">>> x\n"
"[10]"
msgstr ""
">>> x = []\n"
">>> y = x\n"
">>> y.append(10)\n"
">>> y\n"
"[10]\n"
">>> x\n"
"[10]"
msgid "you might be wondering why appending an element to ``y`` changed ``x`` too."
msgstr "شاید برایتان پرسش شده باشد که چرا افزودن یک عنصر به ``y``، ``x`` را نیز تغییر داد."
msgid "There are two factors that produce this result:"
msgstr "دو عامل وجود دارند که این نتیجه را ایجاد میکنند:"
msgid "Variables are simply names that refer to objects. Doing ``y = x`` doesn't create a copy of the list -- it creates a new variable ``y`` that refers to the same object ``x`` refers to. This means that there is only one object (the list), and both ``x`` and ``y`` refer to it."
msgstr "متغیرها صرفاً نامهایی هستند که به شیءها ارجاع میدهند. با انجام ``y = x`` رونوشتی از فهرست ایجاد نمیشود، بلکه یک متغیر جدید ``y`` ایجاد میشود که به همان شیئی ارجاع میدهد که ``x`` به آن ارجاع میدهد. این بدان معناست که تنها یک شیء (فهرست) وجود دارد و هر دو ``x`` و ``y`` به آن ارجاع میدهند."
msgid "Lists are :term:`mutable`, which means that you can change their content."
msgstr "فهرستها :term:`تغییرپذیر <mutable>` هستند، به این معنا که میتوانید محتوای آنها را تغییر دهید."
msgid "After the call to :meth:`~sequence.append`, the content of the mutable object has changed from ``[]`` to ``[10]``. Since both the variables refer to the same object, using either name accesses the modified value ``[10]``."
msgstr "پس از فراخوانی :meth:`~sequence.append`، محتوای شیء تغییرپذیر از ``[]`` به ``[10]`` تغییر کرده است. از آنجا که هر دو متغیر به یک شیء ارجاع دارند، با استفاده از هر یک از نامها میتوان به مقدار تغییرکرده ``[10]`` دسترسی پیدا کرد."
msgid "If we instead assign an immutable object to ``x``::"
msgstr "اگر بهجای آن یک شیء تغییرناپذیر را به ``x`` انتساب دهیم::"
msgid ""
">>> x = 5 # ints are immutable\n"
">>> y = x\n"
">>> x = x + 1 # 5 can't be mutated, we are creating a new object here\n"
">>> x\n"
"6\n"
">>> y\n"
"5"
msgstr ""
">>> x = 5 # ints are immutable\n"
">>> y = x\n"
">>> x = x + 1 # 5 can't be mutated, we are creating a new object here\n"
">>> x\n"
"6\n"
">>> y\n"
"5"
msgid "we can see that in this case ``x`` and ``y`` are not equal anymore. This is because integers are :term:`immutable`, and when we do ``x = x + 1`` we are not mutating the int ``5`` by incrementing its value; instead, we are creating a new object (the int ``6``) and assigning it to ``x`` (that is, changing which object ``x`` refers to). After this assignment we have two objects (the ints ``6`` and ``5``) and two variables that refer to them (``x`` now refers to ``6`` but ``y`` still refers to ``5``)."
msgstr "میتوانیم ببینیم که در این حالت ``x`` و ``y`` دیگر برابر نیستند. این به این دلیل است که اعداد صحیح :term:`تغییرناپذیر <immutable>` هستند، و هنگامی که ``x = x + 1`` را اجرا میکنیم، با افزایش مقدار آن، عدد صحیح ``5`` را تغییر نمیدهیم؛ در عوض، یک شیء جدید (عدد صحیح ``6``) ایجاد میکنیم و آن را به ``x`` اختصاص میدهیم (یعنی اینکه ``x`` به کدام شیء ارجاع دارد را تغییر میدهیم). پس از این انتساب، دو شیء (اعداد صحیح ``6`` و ``5``) و دو متغیر داریم که به آنها ارجاع دارند (``x`` اکنون به ``6`` ارجاع دارد اما ``y`` هنوز به ``5`` ارجاع دارد)."
msgid "Some operations (for example ``y.append(10)`` and ``y.sort()``) mutate the object, whereas superficially similar operations (for example ``y = y + [10]`` and :func:`sorted(y) <sorted>`) create a new object. In general in Python (and in all cases in the standard library) a method that mutates an object will return ``None`` to help avoid getting the two types of operations confused. So if you mistakenly write ``y.sort()`` thinking it will give you a sorted copy of ``y``, you'll instead end up with ``None``, which will likely cause your program to generate an easily diagnosed error."
msgstr "برخی عملیات (برای مثال ``y.append(10)`` و ``y.sort()``) شیء را تغییر میدهند، در حالی که عملیات ظاهراً مشابه (برای مثال ``y = y + [10]`` و :func:`sorted(y) <sorted>`) شیء جدیدی ایجاد میکنند. بهطور کلی در پایتون (و در همه موارد در کتابخانه استاندارد)، متدی که یک شیء را تغییر میدهد مقدار ``None`` را برمیگرداند تا کمک کند این دو نوع عملیات با هم اشتباه گرفته نشوند. بنابراین اگر بهاشتباه ``y.sort()`` را بنویسید و فکر کنید که نسخهای مرتبشده از ``y`` به شما میدهد، در عوض مقدار ``None`` دریافت خواهید کرد که احتمالاً باعث میشود برنامه شما خطایی تولید کند که بهراحتی قابل تشخیص است."
msgid "However, there is one class of operations where the same operation sometimes has different behaviors with different types: the augmented assignment operators. For example, ``+=`` mutates lists but not tuples or ints (``a_list += [1, 2, 3]`` is equivalent to ``a_list.extend([1, 2, 3])`` and mutates ``a_list``, whereas ``some_tuple += (1, 2, 3)`` and ``some_int += 1`` create new objects)."
msgstr "با این حال، دستهای از عملیات وجود دارد که در آنها یک عملیات واحد گاهی با انواع مختلف رفتارهای متفاوتی دارد: عملگرهای انتساب افزوده. برای مثال، ``+=`` فهرستها را تغییر میدهد، اما تاپلها یا اعداد صحیح را تغییر نمیدهد (``a_list += [1, 2, 3]`` معادل ``a_list.extend([1, 2, 3])`` است و ``a_list`` را تغییر میدهد، در حالی که ``some_tuple += (1, 2, 3)`` و ``some_int += 1`` اشیاء جدیدی ایجاد میکنند)."
msgid "In other words:"
msgstr "به عبارت دیگر:"
msgid "If we have a mutable object (such as :class:`list`, :class:`dict`, :class:`set`), we can use some specific operations to mutate it and all the variables that refer to it will see the change."
msgstr "اگر یک شیء تغییرپذیر (مانند :class:`list`، :class:`dict`، :class:`set`) داشته باشیم، میتوانیم از برخی عملیات خاص برای تغییر آن استفاده کنیم و همه متغیرهایی که به آن ارجاع دارند، تغییر را خواهند دید."
msgid "If we have an immutable object (such as :class:`str`, :class:`int`, :class:`tuple`), all the variables that refer to it will always see the same value, but operations that transform that value into a new value always return a new object."
msgstr "اگر یک شیء تغییرناپذیر داشته باشیم (مانند :class:`str`، :class:`int`، :class:`tuple`)، همه متغیرهایی که به آن ارجاع میکنند همیشه مقدار یکسانی را مشاهده خواهند کرد، اما عملیاتی که آن مقدار را به مقدار جدیدی تبدیل میکنند همیشه شیء جدیدی را برمیگردانند."
msgid "If you want to know if two variables refer to the same object or not, you can use the :keyword:`is` operator, or the built-in function :func:`id`."
msgstr "اگر میخواهید بدانید که آیا دو متغیر به یک شیء ارجاع میدهند یا خیر، میتوانید از عملگر :keyword:`is` یا تابع توکار :func:`id` استفاده کنید."
msgid "How do I write a function with output parameters (call by reference)?"
msgstr "چگونه تابعی با پارامترهای خروجی (فراخوانی با ارجاع) بنویسم؟"
msgid "Remember that arguments are passed by assignment in Python. Since assignment just creates references to objects, there's no alias between an argument name in the caller and callee, and consequently no call-by-reference. You can achieve the desired effect in a number of ways."
msgstr "به یاد داشته باشید که آرگومانها در پایتون با انتساب ارسال میشوند. از آنجا که انتساب صرفاً ارجاعهایی به شیءها ایجاد میکند، هیچ نام مستعاری بین نام یک آرگومان در فراخواننده و فراخوانده وجود ندارد و در نتیجه هیچ فراخوانی با ارجاعی وجود ندارد. شما میتوانید به روشهای گوناگونی به اثر مطلوب دست یابید."
msgid "By returning a tuple of the results::"
msgstr "با برگرداندن یک تاپل از نتایج::"
msgid ""
">>> def func1(a, b):\n"
"... a = 'new-value' # a and b are local names\n"
"... b = b + 1 # assigned to new objects\n"
"... return a, b # return new values\n"
"...\n"
">>> x, y = 'old-value', 99\n"
">>> func1(x, y)\n"
"('new-value', 100)"
msgstr ""
">>> def func1(a, b):\n"
"... a = 'new-value' # a and b are local names\n"
"... b = b + 1 # assigned to new objects\n"
"... return a, b # return new values\n"
"...\n"
">>> x, y = 'old-value', 99\n"
">>> func1(x, y)\n"
"('new-value', 100)"
msgid "This is almost always the clearest solution."
msgstr "این تقریباً همیشه واضحترین راهحل است."
msgid "By using global variables. This isn't thread-safe, and is not recommended."
msgstr "با استفاده از متغیرهای سراسری. این روش ایمن نسبت به نخ (thread-safe) نیست و توصیه نمیشود."
msgid "By passing a mutable (changeable in-place) object::"
msgstr "با ارسال یک شیء تغییرپذیر (قابل تغییر بهصورت درجا)::"
msgid ""
">>> def func2(a):\n"
"... a[0] = 'new-value' # 'a' references a mutable list\n"
"... a[1] = a[1] + 1 # changes a shared object\n"
"...\n"
">>> args = ['old-value', 99]\n"
">>> func2(args)\n"
">>> args\n"
"['new-value', 100]"
msgstr ""
">>> def func2(a):\n"
"... a[0] = 'new-value' # 'a' references a mutable list\n"
"... a[1] = a[1] + 1 # changes a shared object\n"
"...\n"
">>> args = ['old-value', 99]\n"
">>> func2(args)\n"
">>> args\n"
"['new-value', 100]"
msgid "By passing in a dictionary that gets mutated::"
msgstr "با پاس دادن یک دیکشنری که تغییر مییابد::"
msgid ""
">>> def func3(args):\n"
"... args['a'] = 'new-value' # args is a mutable dictionary\n"
"... args['b'] = args['b'] + 1 # change it in-place\n"
"...\n"
">>> args = {'a': 'old-value', 'b': 99}\n"
">>> func3(args)\n"
">>> args\n"
"{'a': 'new-value', 'b': 100}"
msgstr ""
">>> def func3(args):\n"
"... args['a'] = 'new-value' # args is a mutable dictionary\n"
"... args['b'] = args['b'] + 1 # change it in-place\n"
"...\n"
">>> args = {'a': 'old-value', 'b': 99}\n"
">>> func3(args)\n"
">>> args\n"
"{'a': 'new-value', 'b': 100}"
msgid "Or bundle up values in a class instance::"
msgstr "یا مقادیر را در یک نمونه کلاس دستهبندی کنید::"
msgid ""
">>> class Namespace:\n"
"... def __init__(self, /, **args):\n"
"... for key, value in args.items():\n"
"... setattr(self, key, value)\n"
"...\n"
">>> def func4(args):\n"
"... args.a = 'new-value' # args is a mutable Namespace\n"
"... args.b = args.b + 1 # change object in-place\n"
"...\n"
">>> args = Namespace(a='old-value', b=99)\n"
">>> func4(args)\n"
">>> vars(args)\n"
"{'a': 'new-value', 'b': 100}"
msgstr ""
">>> class Namespace:\n"
"... def __init__(self, /, **args):\n"
"... for key, value in args.items():\n"
"... setattr(self, key, value)\n"
"...\n"
">>> def func4(args):\n"
"... args.a = 'new-value' # args is a mutable Namespace\n"
"... args.b = args.b + 1 # change object in-place\n"
"...\n"
">>> args = Namespace(a='old-value', b=99)\n"
">>> func4(args)\n"
">>> vars(args)\n"
"{'a': 'new-value', 'b': 100}"
msgid "There's almost never a good reason to get this complicated."
msgstr "تقریباً هرگز دلیل خوبی برای اینقدر پیچیده شدن وجود ندارد."
msgid "Your best choice is to return a tuple containing the multiple results."
msgstr "بهترین انتخاب شما برگرداندن یک تاپل حاوی نتایج متعدد است."
msgid "How do you make a higher order function in Python?"
msgstr "چگونه در پایتون یک تابع مرتبه بالاتر میسازید؟"
msgid "You have two choices: you can use nested scopes or you can use callable objects. For example, suppose you wanted to define ``linear(a,b)`` which returns a function ``f(x)`` that computes the value ``a*x+b``. Using nested scopes::"
msgstr "شما دو گزینه دارید: میتوانید از محدودههای تودرتو یا از اشیای فراخوانیپذیر استفاده کنید. برای مثال، فرض کنید میخواهید ``linear(a,b)`` را تعریف کنید که تابع ``f(x)`` را برمیگرداند؛ تابعی که مقدار ``a*x+b`` را محاسبه میکند. با استفاده از محدودههای تودرتو::"
msgid ""
"def linear(a, b):\n"
" def result(x):\n"
" return a * x + b\n"
" return result"
msgstr ""
"def linear(a, b):\n"
" def result(x):\n"
" return a * x + b\n"
" return result"
msgid "Or using a callable object::"
msgstr "یا با استفاده از یک شیء فراخوانیپذیر::"
msgid ""
"class linear:\n"
"\n"
" def __init__(self, a, b):\n"
" self.a, self.b = a, b\n"
"\n"
" def __call__(self, x):\n"
" return self.a * x + self.b"
msgstr ""
"class linear:\n"
"\n"
" def __init__(self, a, b):\n"
" self.a, self.b = a, b\n"
"\n"
" def __call__(self, x):\n"
" return self.a * x + self.b"
msgid "In both cases, ::"
msgstr "در هر دو مورد، ::"
msgid "taxes = linear(0.3, 2)"
msgstr "taxes = linear(0.3, 2)"
msgid "gives a callable object where ``taxes(10e6) == 0.3 * 10e6 + 2``."
msgstr "یک شیء فراخوانیپذیر میدهد که در آن ``taxes(10e6) == 0.3 * 10e6 + 2``."
msgid "The callable object approach has the disadvantage that it is a bit slower and results in slightly longer code. However, note that a collection of callables can share their signature via inheritance::"
msgstr "رویکرد شیء فراخوانیپذیر این عیب را دارد که کمی کندتر است و منجر به کد کمی طولانیتر میشود. با این حال، توجه داشته باشید که مجموعهای از اشیاء فراخوانیپذیر میتوانند امضای خود را از طریق ارثبری به اشتراک بگذارند::"
msgid ""
"class exponential(linear):\n"
" # __init__ inherited\n"
" def __call__(self, x):\n"
" return self.a * (x ** self.b)"
msgstr ""
"class exponential(linear):\n"
" # __init__ inherited\n"
" def __call__(self, x):\n"
" return self.a * (x ** self.b)"
msgid "Object can encapsulate state for several methods::"
msgstr "شیء میتواند وضعیت را برای چندین متد کپسوله کند::"
msgid ""
"class counter:\n"
"\n"
" value = 0\n"
"\n"
" def set(self, x):\n"
" self.value = x\n"
"\n"
" def up(self):\n"
" self.value = self.value + 1\n"
"\n"
" def down(self):\n"
" self.value = self.value - 1\n"
"\n"
"count = counter()\n"
"inc, dec, reset = count.up, count.down, count.set"
msgstr ""
"class counter:\n"
"\n"
" value = 0\n"
"\n"
" def set(self, x):\n"
" self.value = x\n"
"\n"
" def up(self):\n"
" self.value = self.value + 1\n"
"\n"
" def down(self):\n"
" self.value = self.value - 1\n"
"\n"
"count = counter()\n"
"inc, dec, reset = count.up, count.down, count.set"
msgid "Here ``inc()``, ``dec()`` and ``reset()`` act like functions which share the same counting variable."
msgstr "در اینجا ``inc()``، ``dec()`` و ``reset()`` مانند توابعی عمل میکنند که متغیر شمارندهی یکسانی را به اشتراک میگذارند."
msgid "How do I copy an object in Python?"
msgstr "چگونه میتوانم یک شیء را در پایتون کپی کنم؟"
msgid "In general, try :func:`copy.copy` or :func:`copy.deepcopy` for the general case. Not all objects can be copied, but most can."
msgstr "بهطور کلی، برای حالت عمومی، :func:`copy.copy` یا :func:`copy.deepcopy` را امتحان کنید. همهی اشیاء قابل کپی نیستند، اما بیشتر آنها قابل کپی هستند."
msgid "Some objects can be copied more easily. Dictionaries have a :meth:`~dict.copy` method::"
msgstr "برخی از اشیاء را میتوان بهسادگی بیشتری کپی کرد. دیکشنریها دارای متد :meth:`~dict.copy` هستند::"
msgid "newdict = olddict.copy()"
msgstr "newdict = olddict.copy()"
msgid "Sequences can be copied by slicing::"
msgstr "دنبالهها را میتوان با اسلایس کردن کپی کرد::"
msgid "new_l = l[:]"
msgstr "new_l = l[:]"
msgid "How can I find the methods or attributes of an object?"
msgstr "چگونه میتوانم متدها یا ویژگیهای یک شیء را پیدا کنم؟"
msgid "For an instance ``x`` of a user-defined class, :func:`dir(x) <dir>` returns an alphabetized list of the names containing the instance attributes and methods and attributes defined by its class."
msgstr "برای یک نمونه ``x`` از یک کلاس تعریفشده توسط کاربر، :func:`dir(x) <dir>` فهرستی مرتبشده به ترتیب الفبا از نامها را برمیگرداند که شامل ویژگیهای نمونه، متدها و ویژگیهای تعریفشده توسط کلاس آن است."
msgid "How can my code discover the name of an object?"
msgstr "کد من چگونه میتواند نام یک شیء را کشف کند؟"
msgid "Generally speaking, it can't, because objects don't really have names. Essentially, assignment always binds a name to a value; the same is true of ``def`` and ``class`` statements, but in that case the value is a callable. Consider the following code::"
msgstr "بهطور کلی، امکانپذیر نیست، زیرا اشیاء واقعاً نام ندارند. در اصل، انتساب همیشه یک نام را به یک مقدار مقید میکند؛ همین موضوع برای دستورهای ``def`` و ``class`` نیز صادق است، اما در آن حالت مقدار یک فراخوانیپذیر است. کد زیر را در نظر بگیرید::"
msgid ""
">>> class A:\n"
"... pass\n"
"...\n"
">>> B = A\n"
">>> a = B()\n"
">>> b = a\n"
">>> print(b)\n"
"<__main__.A object at 0x16D07CC>\n"
">>> print(a)\n"
"<__main__.A object at 0x16D07CC>"
msgstr ""
">>> class A:\n"
"... pass\n"
"...\n"
">>> B = A\n"
">>> a = B()\n"
">>> b = a\n"
">>> print(b)\n"
"<__main__.A object at 0x16D07CC>\n"
">>> print(a)\n"
"<__main__.A object at 0x16D07CC>"
msgid "Arguably the class has a name: even though it is bound to two names and invoked through the name ``B`` the created instance is still reported as an instance of class ``A``. However, it is impossible to say whether the instance's name is ``a`` or ``b``, since both names are bound to the same value."
msgstr "میتوان گفت که کلاس دارای نام است: با وجود اینکه به دو نام مقید است و از طریق نام ``B`` فراخوانی میشود، نمونهی ایجادشده همچنان بهعنوان نمونهای از کلاس ``A`` گزارش میشود. با این حال، نمیتوان گفت که نام نمونه ``a`` است یا ``b``، زیرا هر دو نام به یک مقدار مقید هستند."
msgid "Generally speaking it should not be necessary for your code to \"know the names\" of particular values. Unless you are deliberately writing introspective programs, this is usually an indication that a change of approach might be beneficial."
msgstr "بهطور کلی، نباید ضرورتی داشته باشد که کد شما «نامهای مقادیر خاص را بداند». مگر اینکه عمداً در حال نوشتن برنامههای دروننگر (introspective) باشید، این معمولاً نشانهای است که تغییر رویکرد ممکن است مفید باشد."
msgid "In comp.lang.python, Fredrik Lundh once gave an excellent analogy in answer to this question:"
msgstr "در comp.lang.python، Fredrik Lundh یکبار تمثیلی عالی در پاسخ به این پرسش ارائه کرد:"
msgid "The same way as you get the name of that cat you found on your porch: the cat (object) itself cannot tell you its name, and it doesn't really care -- so the only way to find out what it's called is to ask all your neighbours (namespaces) if it's their cat (object)..."
msgstr "به همان شیوهای که نام آن گربهای را که در ایوان خود پیدا کردهاید میفهمید: خود گربه (شیء) نمیتواند نامش را به شما بگوید، و واقعاً برایش اهمیتی ندارد — بنابراین تنها راه برای فهمیدن نام آن این است که از همه همسایههایتان (فضای نامها) بپرسید که آیا این گربه، گربهی آنها (شیء) است یا خیر..."
msgid "....and don't be surprised if you'll find that it's known by many names, or no name at all!"
msgstr "....و تعجب نکنید اگر متوجه شدید که با نامهای بسیاری شناخته میشود، یا اصلاً نامی ندارد!"
msgid "What's up with the comma operator's precedence?"
msgstr "وضعیت اولویت عملگر ویرگول چیست؟"
msgid "Comma is not an operator in Python. Consider this session::"
msgstr "کاما در پایتون عملگر نیست. این نشست را در نظر بگیرید::"
msgid ""
">>> \"a\" in \"b\", \"a\"\n"
"(False, 'a')"
msgstr ""
">>> \"a\" in \"b\", \"a\"\n"
"(False, 'a')"
msgid "Since the comma is not an operator, but a separator between expressions the above is evaluated as if you had entered::"
msgstr "از آنجا که کاما یک عملگر نیست، بلکه جداکنندهای بین عبارتها است، مورد بالا طوری ارزیابی میشود که گویی شما وارد کردهاید::"
msgid "(\"a\" in \"b\"), \"a\""
msgstr "(\"a\" in \"b\"), \"a\""
msgid "not::"
msgstr "not::"
msgid "\"a\" in (\"b\", \"a\")"
msgstr "\"a\" in (\"b\", \"a\")"
msgid "The same is true of the various assignment operators (``=``, ``+=``, and so on). They are not truly operators but syntactic delimiters in assignment statements."
msgstr "همین موضوع در مورد انواع عملگرهای انتساب (``=``، ``+=`` و غیره) نیز صادق است. آنها واقعاً عملگر نیستند، بلکه جداکنندههای نحوی در دستورات انتساب هستند."
msgid "Is there an equivalent of C's \"?:\" ternary operator?"
msgstr "آیا معادلی برای عملگر سهگانهی \"?:\" در C وجود دارد؟"
msgid "Yes, there is. The syntax is as follows::"
msgstr "بله، وجود دارد. سینتکس به صورت زیر است::"
msgid ""
"[on_true] if [expression] else [on_false]\n"
"\n"
"x, y = 50, 25\n"
"small = x if x < y else y"
msgstr ""
"[on_true] if [expression] else [on_false]\n"
"\n"
"x, y = 50, 25\n"
"small = x if x < y else y"
msgid "Before this syntax was introduced in Python 2.5, a common idiom was to use logical operators::"
msgstr "پیش از معرفی این سینتکس در Python 2.5، الگوی رایج این بود که از عملگرهای منطقی استفاده شود::"
msgid "[expression] and [on_true] or [on_false]"
msgstr "[expression] and [on_true] or [on_false]"
msgid "However, this idiom is unsafe, as it can give wrong results when *on_true* has a false boolean value. Therefore, it is always better to use the ``... if ... else ...`` form."
msgstr "با این حال، این شیوه ناامن است، زیرا هنگامی که *on_true* مقدار بولی نادرست داشته باشد، میتواند نتایج اشتباهی بدهد. بنابراین، همیشه بهتر است از قالب ``... if ... else ...`` استفاده کنید."
msgid "Is it possible to write obfuscated one-liners in Python?"
msgstr "آیا امکان نوشتن تکسطریهای مبهم در پایتون وجود دارد؟"
msgid "Yes. Usually this is done by nesting :keyword:`lambda` within :keyword:`!lambda`. See the following three examples, slightly adapted from Ulf Bartelt::"
msgstr "بله. معمولاً این کار با تودرتو کردن :keyword:`lambda` درون :keyword:`!lambda` انجام میشود. ۳ مثال زیر را ببینید، که اندکی از Ulf Bartelt اقتباس شدهاند::"
msgid ""
"from functools import reduce\n"
"\n"
"# Primes < 1000\n"
"print(list(filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,\n"
"map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000)))))\n"
"\n"
"# First 10 Fibonacci numbers\n"
"print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1:\n"
"f(x,f), range(10))))\n"
"\n"
"# Mandelbrot set\n"
"print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\\n'+y,map(lambda y,\n"
"Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,\n"
"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,\n"
"i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y\n"
">=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(\n"
"64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy\n"
"))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24))\n"
"# \\___ ___/ \\___ ___/ | | |__ lines on screen\n"
"# V V | |______ columns on screen\n"
"# | | |__________ maximum of \"iterations\"\n"
"# | |_________________ range on y axis\n"
"# |____________________________ range on x axis"
msgstr ""
"from functools import reduce\n"
"\n"
"# Primes < 1000\n"
"print(list(filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,\n"
"map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000)))))\n"
"\n"
"# First 10 Fibonacci numbers\n"
"print(list(map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1:\n"
"f(x,f), range(10))))\n"
"\n"
"# Mandelbrot set\n"
"print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\\n'+y,map(lambda y,\n"
"Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,\n"
"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,\n"
"i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y\n"
">=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(\n"
"64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy\n"
"))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24))\n"
"# \\___ ___/ \\___ ___/ | | |__ lines on screen\n"
"# V V | |______ columns on screen\n"
"# | | |__________ maximum of \"iterations\"\n"
"# | |_________________ range on y axis\n"
"# |____________________________ range on x axis"
msgid "Don't try this at home, kids!"
msgstr "بچهها، این کار را در خانه امتحان نکنید!"
msgid "What does the slash(/) in the parameter list of a function mean?"
msgstr "اسلش (/) در فهرست پارامترهای یک تابع چه معنایی دارد؟"
msgid "A slash in the argument list of a function denotes that the parameters prior to it are positional-only. Positional-only parameters are the ones without an externally usable name. Upon calling a function that accepts positional-only parameters, arguments are mapped to parameters based solely on their position. For example, :func:`divmod` is a function that accepts positional-only parameters. Its documentation looks like this::"
msgstr "اسلش در فهرست آرگومانهای یک تابع نشان میدهد که پارامترهای پیش از آن فقط جایگاهی هستند. پارامترهای فقط جایگاهی، پارامترهایی بدون نام قابل استفاده از بیرون هستند. هنگام فراخوانی تابعی که پارامترهای فقط جایگاهی میپذیرد، آرگومانها صرفاً بر اساس جایگاهشان به پارامترها نگاشت میشوند. برای مثال، :func:`divmod` تابعی است که پارامترهای فقط جایگاهی میپذیرد. مستندات آن به این شکل است::"
msgid ""
">>> help(divmod)\n"
"Help on built-in function divmod in module builtins:\n"
"\n"
"divmod(x, y, /)\n"
" Return the tuple (x//y, x%y). Invariant: div*y + mod == x."
msgstr ""
">>> help(divmod)\n"
"Help on built-in function divmod in module builtins:\n"
"\n"
"divmod(x, y, /)\n"
" Return the tuple (x//y, x%y). Invariant: div*y + mod == x."
msgid "The slash at the end of the parameter list means that both parameters are positional-only. Thus, calling :func:`divmod` with keyword arguments would lead to an error::"
msgstr "اسلش در انتهای فهرست پارامترها به این معناست که هر دو پارامتر فقط جایگاهی هستند. بنابراین، فراخوانی :func:`divmod` با آرگومانهای کلیدواژهای منجر به خطا خواهد شد::"
msgid ""
">>> divmod(x=3, y=4)\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"TypeError: divmod() takes no keyword arguments"
msgstr ""
">>> divmod(x=3, y=4)\n"
"Traceback (most recent call last):\n"
" File \"<stdin>\", line 1, in <module>\n"
"TypeError: divmod() takes no keyword arguments"
msgid "Numbers and strings"
msgstr "اعداد و رشتهها"
msgid "How do I specify hexadecimal and octal integers?"
msgstr "چگونه میتوانم اعداد صحیح مبنای شانزده و مبنای هشت را مشخص کنم؟"
msgid "To specify an octal digit, precede the octal value with a zero, and then a lower or uppercase \"o\". For example, to set the variable \"a\" to the octal value \"10\" (8 in decimal), type::"
msgstr "برای مشخص کردن یک رقم مبنای هشت، پیش از مقدار مبنای هشت یک صفر و سپس حرف \"o\" کوچک یا بزرگ قرار دهید. برای مثال، برای تنظیم متغیر \"a\" به مقدار مبنای هشت \"10\" (۸ در مبنای ده)، تایپ کنید::"
msgid ""
">>> a = 0o10\n"
">>> a\n"
"8"
msgstr ""
">>> a = 0o10\n"
">>> a\n"
"8"
msgid "Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero, and then a lower or uppercase \"x\". Hexadecimal digits can be specified in lower or uppercase. For example, in the Python interpreter::"
msgstr "مبنای شانزده هم به همین سادگی است. کافی است پیش از عدد مبنای شانزده، یک صفر و سپس یک «x» کوچک یا بزرگ قرار دهید. ارقام مبنای شانزده را میتوان با حروف کوچک یا بزرگ مشخص کرد. برای مثال، در مفسر پایتون::"
msgid ""
">>> a = 0xa5\n"
">>> a\n"
"165\n"
">>> b = 0XB2\n"
">>> b\n"
"178"
msgstr ""
">>> a = 0xa5\n"
">>> a\n"
"165\n"
">>> b = 0XB2\n"
">>> b\n"
"178"
msgid "Why does -22 // 10 return -3?"
msgstr "چرا -22 // 10 مقدار -3 را برمیگرداند؟"
msgid "It's primarily driven by the desire that ``i % j`` have the same sign as ``j``. If you want that, and also want::"
msgstr "این موضوع عمدتاً ناشی از این خواسته است که ``i % j`` همان علامت ``j`` را داشته باشد. اگر این را میخواهید، و همچنین میخواهید::"
msgid "i == (i // j) * j + (i % j)"
msgstr "i == (i // j) * j + (i % j)"
msgid "then integer division has to return the floor. C also requires that identity to hold, and then compilers that truncate ``i // j`` need to make ``i % j`` have the same sign as ``i``."
msgstr "در این صورت تقسیم عدد صحیح باید مقدار کف (floor) را برگرداند. زبان C نیز برقرار بودن این اتحاد را الزامی میداند، و در این صورت کامپایلرهایی که ``i // j`` را قطع میکنند باید ``i % j`` را همعلامت با ``i`` کنند."
msgid "There are few real use cases for ``i % j`` when ``j`` is negative. When ``j`` is positive, there are many, and in virtually all of them it's more useful for ``i % j`` to be ``>= 0``. If the clock says 10 now, what did it say 200 hours ago? ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to bite."
msgstr "وقتی ``j`` منفی است، موارد استفاده واقعی کمی برای ``i % j`` وجود دارد. وقتی ``j`` مثبت است، موارد زیادی وجود دارد، و تقریباً در همهی آنها، مفیدتر است که ``i % j`` ``>= 0`` باشد. اگر ساعت اکنون ۱۰ باشد، ۲۰۰ ساعت پیش چند بوده است؟ ``-190 % 12 == 2`` مفید است؛ ``-190 % 12 == -10`` باگی است که در کمین نشسته تا مشکلساز شود."
msgid "How do I get int literal attribute instead of SyntaxError?"
msgstr "چگونه میتوانم بهجای SyntaxError، ویژگی لفظی int را دریافت کنم؟"
msgid "Trying to lookup an ``int`` literal attribute in the normal manner gives a :exc:`SyntaxError` because the period is seen as a decimal point::"
msgstr "تلاش برای جستوجوی ویژگی یک لفظی ``int`` به روش معمول باعث :exc:`SyntaxError` میشود، زیرا نقطه بهعنوان نقطهی اعشار در نظر گرفته میشود::"
msgid ""
">>> 1.__class__\n"
" File \"<stdin>\", line 1\n"
" 1.__class__\n"
" ^\n"
"SyntaxError: invalid decimal literal"
msgstr ""
">>> 1.__class__\n"
" File \"<stdin>\", line 1\n"
" 1.__class__\n"
" ^\n"
"SyntaxError: invalid decimal literal"
msgid "The solution is to separate the literal from the period with either a space or parentheses."
msgstr "راهحل این است که لفظی را با یک فاصله یا پرانتز از نقطه جدا کنید."
msgid "How do I convert a string to a number?"
msgstr "چگونه یک رشته را به عدد تبدیل کنم؟"