Type casting data type

how to convert list into complex data type

2 Likes

@narojuramakrishna11

you can convert a list into a complex data type using the complex() function. The complex() function takes two arguments, the real part and the imaginary part of the complex number. To convert a list into a complex number, you can unpack the list into two variables and pass them as arguments to the complex() function.

Example:
my_list = [3.5, 2.1]
my_complex = complex(*my_list)
print(my_complex) # Output: (3.5+2.1j)

2 Likes