Complex Numbers
00:06 A complex number is expressed in the form of ax + bj. It has two elements—the real element and the imaginary part, where j is the square root of -1.
00:21 If your maths has gone to a certain level, you probably have come across complex and imaginary numbers. They’re useful in a number of fields and Python is perfectly happy dealing with them.
00:34
Creating complex numbers is easily done as you can see here. The form a = 2+3j
gives us a
, and if we look at the type of a
, you can see it’s of the <class 'complex'>
. In this class, it’s possible to do mathematical operations, such as addition.
00:54
Let’s define another number b = 3+5j
.
01:02
Adding a + b
gives us what we’d expect, (5+8j)
. You can multiply them, such as a * a
gives us (-5+12j)
.
01:16 Complex numbers in Python are capable of doing any of the sort of arithmetic as you’d expect to be able to do with them in mathematical work. So if you’re doing anything that involves complex numbers, you’ll be able to use this data type to allow you to do it simply and easily.
Become a Member to join the conversation.
alvesmig on Feb. 5, 2024
Hi, a complex number is expressed in the form
a + bj
and not like showed in the slideax + bj
.PS: I like your teaching style.
Best regards Miguel