# تنقيح أخطاء النص البرمجي في بايثون باستخدام تنقيح f string

**URL:** <https://discourse.aosus.org/t/topic/2426>\
**Category:** البرمجة\
**Tags:** python, برمجة\
**Created:** [13 مايو 2022، 6:24ص UTC](https://discourse.aosus.org/t/topic/2426 "2022-05-13T06:24:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![greentip](https://discourse.aosus.org/letter_avatar_proxy/v4/letter/g/b5ac83/32.png) [@greentip](https://discourse.aosus.org/u/greentip)\
**Post date:** [13 مايو 2022، 6:24ص UTC](https://discourse.aosus.org/t/topic/2426/1 "2022-05-13T06:24:04Z")

</div>

﷽

السلام عليكم ورحمة الله وبركاته

أثناء العمل على النص البرمجي يحتاج المبرمج لوضع بعض النصوص التي تكشف عن تقدم العمل وتظهر بعض المتغيرات وغير ذلك مما يساعد في كشف الأخطاء. من الوسائل المتبعة هي استخدام الأمر `print` .

## الطريقة التقليدية

في الطريقة التقليدية لاستخدام أمر الطباعة ننفذطباعة المتغير أو المعادلة هكذا  
مثلا:

```python
a = 2
b = 2
print(a+b)

```

يعطي

```auto
4

```

لكن عندما يكون عندنا كثير من المعاملات الحسابية سنحتاج لمعرفة أي معاملة أتت بالنتيجة 4 وأيها جاءت بغير ذلك. وهنا يمكن طباعة شيء مثل:

```python
print("a+b =", a+b)

```

وهذا سيعطينا:

```python
a+b = 4

```

القسم الأول a+b يدوي كتبناه بيدنا والثاني 4 هو نتيجة الجمع.

لكن احتجنا لكتابة المعادلة (a+b) مرتين مرة لتطبع كنص ومرة لتطبع نتيجتها فما الحل؟

## f string طريقة

لتسهيل الأمر يمكننا استخدام f string debugging

يمكن اختصار طباعة رسائل الخطأ وغيرها باستخدام هذا النمط المختصر:

```python
a =2
b =2
print(f"{a+b = }")

```

والنيتجة هي نفسها:

```python
a+b = 4

```

لقراءة المزيد عن f string debugging:

> **[f-string debugging in Python 3.8](https://tirkarthi.github.io/programming/2019/05/08/f-string-debugging.html)**
>
> print style debugging is a form of debugging where print statements are inserted to print values of expressions or variables that we need to track. loggers a...

> **[await - 2. Lexical analysis](https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals)**
>
> String literals are text enclosed in single quotes (') or double quotes ("). For example: | A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer(also known as the tokenizer). This chapter...

## هذا الموضوع فائز [بجائزة أسس للكتابة](https://aosus.org/writing-contest)

هذا الموضوع فائز [بجائزة أسس للكتابة](https://aosus.org/writing-contest) وهي اول جائزة عربية مخصصة للكتابة عن البرمجيات الحرة والمفتوحة.

الموضوع متوفر على مدونة gnulinuxsa هنا:

> **[تنقيح أخطاء النص البرمجي في بايثون باستخدام تنقيح f string - GNU/Linux...](https://gnulinuxsa.org/archives/27963/)**
>
> السلام عليكم ورحمة الله وبركاته أثناء العمل على النص البرمجي يحتاج المبرمج لوضع بعض النصوص التي تكشف
