You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[▶ خب، یک جای کار مشکوک است...](#--خب-یک-جای-کار-مشکوک-است)
166
+
-[ 💡 توضیح](#--توضیح-2)
167
167
-[بخش: متفرقه](#بخش-متفرقه)
168
-
-[▶ `+=` سریعتر است](#--سریعتر-است)
168
+
-[ ▶ `+=` سریعتر است](#---سریعتر-است)
169
169
-[ 💡 توضیح:](#---توضیح)
170
170
-[ ▶ بیایید یک رشتهی بزرگ بسازیم!](#--بیایید-یک-رشتهی-بزرگ-بسازیم)
171
171
-[💡 توضیحات](#-توضیحات-1)
@@ -3427,9 +3427,9 @@ AttributeError: 'A' object has no attribute '__variable'
3427
3427
---
3428
3428
---
3429
3429
3430
-
## Section: Appearances are deceptive!
3430
+
## ‫ بخش: ظاهرها فریبندهاند!
3431
3431
3432
-
### ▶ Skipping lines?
3432
+
### ▶ ‫ خطوط را رد میکند؟
3433
3433
<!-- Example ID: d50bbde1-fb9d-4735-9633-3444b9d2f417 --->
3434
3434
**Output:**
3435
3435
```py
@@ -3439,33 +3439,33 @@ AttributeError: 'A' object has no attribute '__variable'
3439
3439
11
3440
3440
```
3441
3441
3442
-
Wut?
3442
+
‫ چی?
3443
3443
3444
-
**Note:** The easiest way to reproduce this is to simply copy the statements from the above snippet and paste them into your file/shell.
3444
+
‫ **نکته:** سادهترین روش برای بازتولید این رفتار، کپی کردن دستورات از کد بالا و جایگذاری (paste) آنها در فایل یا محیط تعاملی (shell) خودتان است.
3445
3445
3446
-
#### 💡 Explanation
3446
+
#### ‫ 💡 توضیح
3447
3447
3448
-
Some non-Western characters look identical to letters in the English alphabet but are considered distinct by the interpreter.
3448
+
‫ برخی از حروف غیرغربی کاملاً مشابه حروف الفبای انگلیسی به نظر میرسند، اما مفسر پایتون آنها را متفاوت در نظر میگیرد.
3449
3449
3450
3450
```py
3451
-
>>> ord('е') # cyrillic 'e' (Ye)
3451
+
>>> ord('е') # حرف سیریلیک «е» (Ye)
3452
3452
1077
3453
-
>>> ord('e') # latin 'e', as used in English and typed using standard keyboard
3453
+
>>> ord('e') # حرف لاتین «e»، که در انگلیسی استفاده میشود و با صفحهکلید استاندارد تایپ میگردد
3454
3454
101
3455
3455
>>> 'е' == 'e'
3456
3456
False
3457
3457
3458
-
>>> value = 42 # latin e
3459
-
>>> valuе = 23 # cyrillic 'e', Python 2.x interpreter would raise a `SyntaxError` here
3458
+
>>> value = 42 # حرف لاتین e
3459
+
>>> valuе = 23 # حرف سیریلیک «е»؛ مفسر پایتون نسخه ۲ در اینجا خطای `SyntaxError` ایجاد میکند
3460
3460
>>> value
3461
3461
42
3462
3462
```
3463
3463
3464
-
The built-in `ord()` function returns a character's Unicode [code point](https://en.wikipedia.org/wiki/Code_point), and different code positions of Cyrillic 'e' and Latin 'e' justify the behavior of the above example.
3464
+
‫ تابع داخلی `ord()`، [کدپوینت](https://fa.wikipedia.org/wiki/کدپوینت) یونیکد مربوط به یک نویسه را برمیگرداند. موقعیتهای کدی متفاوت برای حرف سیریلیک «е» و حرف لاتین «e»، علت رفتار مثال بالا را توجیه میکنند.
3465
3465
3466
3466
---
3467
3467
3468
-
### ▶ Teleportation
3468
+
### ▶ ‫ تلهپورت کردن
3469
3469
3470
3470
<!-- Example ID: edafe923-0c20-4315-b6e1-0c31abfc38f5 --->
3471
3471
@@ -3474,64 +3474,65 @@ The built-in `ord()` function returns a character's Unicode [code point](https:/
3474
3474
import numpy as np
3475
3475
3476
3476
def energy_send(x):
3477
-
# Initializing a numpy array
3477
+
# مقداردهی اولیه یک آرایه numpy
3478
3478
np.array([float(x)])
3479
3479
3480
3480
def energy_receive():
3481
-
# Return an empty numpy array
3481
+
# بازگرداندن یک آرایهی خالی numpy
3482
3482
return np.empty((), dtype=np.float).tolist()
3483
3483
```
3484
3484
3485
-
**Output:**
3485
+
‫ **خروجی:**
3486
3486
```py
3487
3487
>>> energy_send(123.456)
3488
3488
>>> energy_receive()
3489
3489
123.456
3490
3490
```
3491
3491
3492
-
Where's the Nobel Prize?
3492
+
‫ جایزه نوبل کجاست؟
3493
3493
3494
-
#### 💡 Explanation:
3494
+
#### ‫ 💡 توضیح:
3495
3495
3496
-
* Notice that the numpy array created in the `energy_send` function is not returned, so that memory space is free to reallocate.
3497
-
* `numpy.empty()` returns the next free memory slot without reinitializing it. This memory spot just happens to be the same one that was just freed (usually, but not always).
3496
+
* ‫ توجه کنید که آرایهی numpy ایجادشده در تابع `energy_send` برگردانده نشده است، بنابراین فضای حافظهی آن آزاد شده و مجدداً قابل استفاده است.
3497
+
* ‫ تابع `numpy.empty()` نزدیکترین فضای حافظهی آزاد را بدون مقداردهی مجدد برمیگرداند. این فضای حافظه معمولاً همان فضایی است که بهتازگی آزاد شده است (البته معمولاً این اتفاق میافتد و نه همیشه).
3498
3498
3499
3499
---
3500
3500
3501
-
### ▶ Well, something is fishy...
3501
+
### ▶ ‫ خب، یک جای کار مشکوک است...
3502
3502
<!-- Example ID: cb6a37c5-74f7-44ca-b58c-3b902419b362 --->
3503
3503
```py
3504
3504
def square(x):
3505
3505
"""
3506
-
A simple function to calculate the square of a number by addition.
3506
+
یک تابع ساده برای محاسبهی مربع یک عدد با استفاده از جمع.
3507
3507
"""
3508
3508
sum_so_far = 0
3509
3509
for counter in range(x):
3510
3510
sum_so_far = sum_so_far + x
3511
3511
return sum_so_far
3512
3512
```
3513
3513
3514
-
**Output (Python 2.x):**
3514
+
‫ **خروجی (پایتون 2.X):**
3515
3515
3516
3516
```py
3517
3517
>>> square(10)
3518
3518
10
3519
3519
```
3520
3520
3521
-
Shouldn't that be 100?
3521
+
‫ آیا این نباید ۱۰۰ باشد؟
3522
3522
3523
-
**Note:** If you're not able to reproduce this, try running the file [mixed_tabs_and_spaces.py](/mixed_tabs_and_spaces.py) via the shell.
3523
+
‫ **نکته:** اگر نمیتوانید این مشکل را بازتولید کنید، سعی کنید فایل [mixed_tabs_and_spaces.py](/mixed_tabs_and_spaces.py) را از طریق شِل اجرا کنید.
3524
3524
3525
-
#### 💡 Explanation
3525
+
#### ‫ 💡 توضیح
3526
3526
3527
-
* **Don't mix tabs and spaces!** The character just preceding return is a "tab", and the code is indented by multiple of "4 spaces" elsewhere in the example.
3528
-
* This is how Python handles tabs:
3529
-
3530
-
> First, tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight <...>
3531
-
* So the "tab" at the last line of `square` function is replaced with eight spaces, and it gets into the loop.
3532
-
* Python 3 is kind enough to throw an error for such cases automatically.
3527
+
* ‫ **تبها و فاصلهها (space) را با هم ترکیب نکنید!** کاراکتری که دقیقاً قبل از دستور return آمده یک «تب» است، در حالی که در بقیۀ مثال، کد با مضربی از «۴ فاصله» تورفتگی دارد.
3528
+
* ‫ نحوۀ برخورد پایتون با تبها به این صورت است:
3529
+
3530
+
> ‫ ابتدا تبها (از چپ به راست) با یک تا هشت فاصله جایگزین میشوند بهطوری که تعداد کل کاراکترها تا انتهای آن جایگزینی، مضربی از هشت باشد <...>
3531
+
* ‫ بنابراین «تب» در آخرین خط تابع `square` با هشت فاصله جایگزین شده و به همین دلیل داخل حلقه قرار میگیرد.
3532
+
* ‫ پایتون ۳ آنقدر هوشمند هست که چنین مواردی را بهصورت خودکار با خطا اعلام کند.
3533
+
3534
+
‫ **خروجی (Python 3.x):**
3533
3535
3534
-
**Output (Python 3.x):**
3535
3536
```py
3536
3537
TabError: inconsistent use of tabs and spaces in indentation
3537
3538
```
@@ -3542,7 +3543,7 @@ Shouldn't that be 100?
3542
3543
## بخش: متفرقه
3543
3544
3544
3545
3545
-
### ▶ `+=` سریعتر است
3546
+
### ‫ ▶ `+=` سریعتر است
3546
3547
<!-- Example ID: bfd19c60-a807-4a26-9598-4912b86ddb36 --->
0 commit comments