![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we use complex numbers in Python?
A complex number is a pair of real numbers a and b, most often written as a+bi, or a+ib, where i is called the imaginary unit and acts as a label for the second term. Mathematically, i2 = -1. Sometimes, j is used instead of i.
Here’s how a complex number is assigned to a variable:
>>> a=5+6j >>> a (5+6j) >>> type(a) <class 'complex'>
Python has a built-in function complex() which returns a complex data type.
complex(x) returns a complex number with x as real part and imaginary part as zero. complex(x,y) returns a complex number with x as real part and y as imaginary part.
>>> x=5 >>> complex(x) (5+0j) >>> x=5 >>> y=6 >>> complex(x,y) (5+6j)
Advertisements