61 lines
1.5 KiB
Markdown
61 lines
1.5 KiB
Markdown
---
|
||
title: Python Complex Numbers
|
||
localeTitle: أرقام بيثون معقدة
|
||
---
|
||
الأعداد المركبة لها جزء حقيقي وهمي ، يمثل كل منها رقم نقطة عائمة.
|
||
|
||
يمكن إنشاء الجزء التخيلي من رقم مركب باستخدام حرفي تخيلي ، وينتج عن ذلك رقمًا معقدًا بجزء حقيقي من `0.0` :
|
||
|
||
```python
|
||
>>> a = 3.5j
|
||
>>> type(a)
|
||
<class 'complex'>
|
||
>>> print(a)
|
||
3.5j
|
||
>>> a.real
|
||
0.0
|
||
>>> a.imag
|
||
3.5
|
||
```
|
||
|
||
لا يوجد حرفي لإنشاء رقم مركب بأجزاء حقيقية وغير وهمية. لإنشاء رقم مجمع حقيقي غير صفري ، أضف حرفيًا خياليًا إلى رقم نقطة عائمة:
|
||
|
||
```python
|
||
>>> a = 1.1 + 3.5j
|
||
>>> type(a)
|
||
<class 'complex'>
|
||
>>> print(a)
|
||
(1.1+3.5j)
|
||
>>> a.real
|
||
1.1
|
||
>>> a.imag
|
||
3.5
|
||
```
|
||
|
||
أو استخدام [منشئ المعقد](https://docs.python.org/3/library/functions.html#complex) .
|
||
|
||
```python
|
||
class complex([real[, imag]])
|
||
```
|
||
|
||
يمكن أن تكون الوسيطات المستخدمة في استدعاء المُنشئ المعقد من نوع رقمي (بما في ذلك `complex` ) لأي من المعلمتين:
|
||
|
||
```python
|
||
>>> complex(1, 1)
|
||
(1+1j)
|
||
>>> complex(1j, 1j)
|
||
(-1+1j)
|
||
>>> complex(1.1, 3.5)
|
||
(1.1+3.5j)
|
||
>>> complex(1.1)
|
||
(1.1+0j)
|
||
>>> complex(0, 3.5)
|
||
3.5j
|
||
```
|
||
|
||
A `string` يمكن أن تستخدم أيضا حجة. لا يُسمح بوسيطة ثانية إذا تم استخدام سلسلة كوسيطة
|
||
|
||
```python
|
||
>>> complex("1.1+3.5j")
|
||
(1.1+3.5j)
|
||
``` |