mirror of
https://github.com/satwikkansal/wtfpython
synced 2025-05-19 18:53:46 +02:00
Translate Section: Appearances are deceptive
This commit is contained in:
parent
31bc257d11
commit
7ff1359663
83
translations/fa-farsi/README.md
vendored
83
translations/fa-farsi/README.md
vendored
@ -157,15 +157,15 @@
|
|||||||
- [💡 Explanation:](#-explanation-53)
|
- [💡 Explanation:](#-explanation-53)
|
||||||
- [▶ Let's mangle](#-lets-mangle)
|
- [▶ Let's mangle](#-lets-mangle)
|
||||||
- [💡 Explanation:](#-explanation-54)
|
- [💡 Explanation:](#-explanation-54)
|
||||||
- [Section: Appearances are deceptive!](#section-appearances-are-deceptive)
|
- [ بخش: ظاهرها فریبندهاند!](#-بخش-ظاهرها-فریبندهاند)
|
||||||
- [▶ Skipping lines?](#-skipping-lines)
|
- [▶ خطوط را رد میکند؟](#--خطوط-را-رد-میکند)
|
||||||
- [💡 Explanation](#-explanation-55)
|
- [ 💡 توضیح](#--توضیح)
|
||||||
- [▶ Teleportation](#-teleportation)
|
- [▶ تلهپورت کردن](#--تلهپورت-کردن)
|
||||||
- [💡 Explanation:](#-explanation-56)
|
- [ 💡 توضیح:](#--توضیح-1)
|
||||||
- [▶ Well, something is fishy...](#-well-something-is-fishy)
|
- [▶ خب، یک جای کار مشکوک است...](#--خب-یک-جای-کار-مشکوک-است)
|
||||||
- [💡 Explanation](#-explanation-57)
|
- [ 💡 توضیح](#--توضیح-2)
|
||||||
- [بخش: متفرقه](#بخش-متفرقه)
|
- [بخش: متفرقه](#بخش-متفرقه)
|
||||||
- [▶ `+=` سریعتر است](#--سریعتر-است)
|
- [ ▶ `+=` سریعتر است](#---سریعتر-است)
|
||||||
- [ 💡 توضیح:](#---توضیح)
|
- [ 💡 توضیح:](#---توضیح)
|
||||||
- [ ▶ بیایید یک رشتهی بزرگ بسازیم!](#--بیایید-یک-رشتهی-بزرگ-بسازیم)
|
- [ ▶ بیایید یک رشتهی بزرگ بسازیم!](#--بیایید-یک-رشتهی-بزرگ-بسازیم)
|
||||||
- [💡 توضیحات](#-توضیحات-1)
|
- [💡 توضیحات](#-توضیحات-1)
|
||||||
@ -3427,9 +3427,9 @@ AttributeError: 'A' object has no attribute '__variable'
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
## Section: Appearances are deceptive!
|
## ‫ بخش: ظاهرها فریبندهاند!
|
||||||
|
|
||||||
### ▶ Skipping lines?
|
### ▶ ‫ خطوط را رد میکند؟
|
||||||
<!-- Example ID: d50bbde1-fb9d-4735-9633-3444b9d2f417 --->
|
<!-- Example ID: d50bbde1-fb9d-4735-9633-3444b9d2f417 --->
|
||||||
**Output:**
|
**Output:**
|
||||||
```py
|
```py
|
||||||
@ -3439,33 +3439,33 @@ AttributeError: 'A' object has no attribute '__variable'
|
|||||||
11
|
11
|
||||||
```
|
```
|
||||||
|
|
||||||
Wut?
|
‫ چی?
|
||||||
|
|
||||||
**Note:** The easiest way to reproduce this is to simply copy the statements from the above snippet and paste them into your file/shell.
|
‫ **نکته:** سادهترین روش برای بازتولید این رفتار، کپی کردن دستورات از کد بالا و جایگذاری (paste) آنها در فایل یا محیط تعاملی (shell) خودتان است.
|
||||||
|
|
||||||
#### 💡 Explanation
|
#### ‫ 💡 توضیح
|
||||||
|
|
||||||
Some non-Western characters look identical to letters in the English alphabet but are considered distinct by the interpreter.
|
‫ برخی از حروف غیرغربی کاملاً مشابه حروف الفبای انگلیسی به نظر میرسند، اما مفسر پایتون آنها را متفاوت در نظر میگیرد.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
>>> ord('е') # cyrillic 'e' (Ye)
|
>>> ord('е') # حرف سیریلیک «е» (Ye)
|
||||||
1077
|
1077
|
||||||
>>> ord('e') # latin 'e', as used in English and typed using standard keyboard
|
>>> ord('e') # حرف لاتین «e»، که در انگلیسی استفاده میشود و با صفحهکلید استاندارد تایپ میگردد
|
||||||
101
|
101
|
||||||
>>> 'е' == 'e'
|
>>> 'е' == 'e'
|
||||||
False
|
False
|
||||||
|
|
||||||
>>> value = 42 # latin e
|
>>> value = 42 # حرف لاتین e
|
||||||
>>> valuе = 23 # cyrillic 'e', Python 2.x interpreter would raise a `SyntaxError` here
|
>>> valuе = 23 # حرف سیریلیک «е»؛ مفسر پایتون نسخه ۲ در اینجا خطای `SyntaxError` ایجاد میکند
|
||||||
>>> value
|
>>> value
|
||||||
42
|
42
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
‫ تابع داخلی `ord()`، [کدپوینت](https://fa.wikipedia.org/wiki/کدپوینت) یونیکد مربوط به یک نویسه را برمیگرداند. موقعیتهای کدی متفاوت برای حرف سیریلیک «е» و حرف لاتین «e»، علت رفتار مثال بالا را توجیه میکنند.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### ▶ Teleportation
|
### ▶ ‫ تلهپورت کردن
|
||||||
|
|
||||||
<!-- Example ID: edafe923-0c20-4315-b6e1-0c31abfc38f5 --->
|
<!-- Example ID: edafe923-0c20-4315-b6e1-0c31abfc38f5 --->
|
||||||
|
|
||||||
@ -3474,36 +3474,36 @@ The built-in `ord()` function returns a character's Unicode [code point](https:/
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
def energy_send(x):
|
def energy_send(x):
|
||||||
# Initializing a numpy array
|
# مقداردهی اولیه یک آرایه numpy
|
||||||
np.array([float(x)])
|
np.array([float(x)])
|
||||||
|
|
||||||
def energy_receive():
|
def energy_receive():
|
||||||
# Return an empty numpy array
|
# بازگرداندن یک آرایهی خالی numpy
|
||||||
return np.empty((), dtype=np.float).tolist()
|
return np.empty((), dtype=np.float).tolist()
|
||||||
```
|
```
|
||||||
|
|
||||||
**Output:**
|
‫ **خروجی:**
|
||||||
```py
|
```py
|
||||||
>>> energy_send(123.456)
|
>>> energy_send(123.456)
|
||||||
>>> energy_receive()
|
>>> energy_receive()
|
||||||
123.456
|
123.456
|
||||||
```
|
```
|
||||||
|
|
||||||
Where's the Nobel Prize?
|
‫ جایزه نوبل کجاست؟
|
||||||
|
|
||||||
#### 💡 Explanation:
|
#### ‫ 💡 توضیح:
|
||||||
|
|
||||||
* Notice that the numpy array created in the `energy_send` function is not returned, so that memory space is free to reallocate.
|
* ‫ توجه کنید که آرایهی numpy ایجادشده در تابع `energy_send` برگردانده نشده است، بنابراین فضای حافظهی آن آزاد شده و مجدداً قابل استفاده است.
|
||||||
* `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).
|
* ‫ تابع `numpy.empty()` نزدیکترین فضای حافظهی آزاد را بدون مقداردهی مجدد برمیگرداند. این فضای حافظه معمولاً همان فضایی است که بهتازگی آزاد شده است (البته معمولاً این اتفاق میافتد و نه همیشه).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### ▶ Well, something is fishy...
|
### ▶ ‫ خب، یک جای کار مشکوک است...
|
||||||
<!-- Example ID: cb6a37c5-74f7-44ca-b58c-3b902419b362 --->
|
<!-- Example ID: cb6a37c5-74f7-44ca-b58c-3b902419b362 --->
|
||||||
```py
|
```py
|
||||||
def square(x):
|
def square(x):
|
||||||
"""
|
"""
|
||||||
A simple function to calculate the square of a number by addition.
|
یک تابع ساده برای محاسبهی مربع یک عدد با استفاده از جمع.
|
||||||
"""
|
"""
|
||||||
sum_so_far = 0
|
sum_so_far = 0
|
||||||
for counter in range(x):
|
for counter in range(x):
|
||||||
@ -3511,27 +3511,28 @@ def square(x):
|
|||||||
return sum_so_far
|
return sum_so_far
|
||||||
```
|
```
|
||||||
|
|
||||||
**Output (Python 2.x):**
|
‫ **خروجی (پایتون 2.X):**
|
||||||
|
|
||||||
```py
|
```py
|
||||||
>>> square(10)
|
>>> square(10)
|
||||||
10
|
10
|
||||||
```
|
```
|
||||||
|
|
||||||
Shouldn't that be 100?
|
‫ آیا این نباید ۱۰۰ باشد؟
|
||||||
|
|
||||||
**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.
|
‫ **نکته:** اگر نمیتوانید این مشکل را بازتولید کنید، سعی کنید فایل [mixed_tabs_and_spaces.py](/mixed_tabs_and_spaces.py) را از طریق شِل اجرا کنید.
|
||||||
|
|
||||||
#### 💡 Explanation
|
#### ‫ 💡 توضیح
|
||||||
|
|
||||||
* **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.
|
* ‫ **تبها و فاصلهها (space) را با هم ترکیب نکنید!** کاراکتری که دقیقاً قبل از دستور return آمده یک «تب» است، در حالی که در بقیۀ مثال، کد با مضربی از «۴ فاصله» تورفتگی دارد.
|
||||||
* This is how Python handles tabs:
|
* ‫ نحوۀ برخورد پایتون با تبها به این صورت است:
|
||||||
|
|
||||||
> 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 <...>
|
> ‫ ابتدا تبها (از چپ به راست) با یک تا هشت فاصله جایگزین میشوند بهطوری که تعداد کل کاراکترها تا انتهای آن جایگزینی، مضربی از هشت باشد <...>
|
||||||
* So the "tab" at the last line of `square` function is replaced with eight spaces, and it gets into the loop.
|
* ‫ بنابراین «تب» در آخرین خط تابع `square` با هشت فاصله جایگزین شده و به همین دلیل داخل حلقه قرار میگیرد.
|
||||||
* Python 3 is kind enough to throw an error for such cases automatically.
|
* ‫ پایتون ۳ آنقدر هوشمند هست که چنین مواردی را بهصورت خودکار با خطا اعلام کند.
|
||||||
|
|
||||||
|
‫ **خروجی (Python 3.x):**
|
||||||
|
|
||||||
**Output (Python 3.x):**
|
|
||||||
```py
|
```py
|
||||||
TabError: inconsistent use of tabs and spaces in indentation
|
TabError: inconsistent use of tabs and spaces in indentation
|
||||||
```
|
```
|
||||||
@ -3542,7 +3543,7 @@ Shouldn't that be 100?
|
|||||||
## بخش: متفرقه
|
## بخش: متفرقه
|
||||||
|
|
||||||
|
|
||||||
### ▶ `+=` سریعتر است
|
### ‫ ▶ `+=` سریعتر است
|
||||||
<!-- Example ID: bfd19c60-a807-4a26-9598-4912b86ddb36 --->
|
<!-- Example ID: bfd19c60-a807-4a26-9598-4912b86ddb36 --->
|
||||||
|
|
||||||
```py
|
```py
|
||||||
|
Loading…
x
Reference in New Issue
Block a user