How to Set the Output Type of Complex Number Calculation (a+jb+c+jd; a, b, c, d:real)

Asked 2 years ago, Updated 2 years ago, 33 views

The output of the complex number calculation (a+jb+c+jd;a,b,c,d:real) is 1.23-0j.
How do I print 1.23? # Not an array.

python python3

2022-09-30 14:07

1 Answers

Redefine the repr() of the complex class, or set z=a+jb+c+jd;z.real if z.imag==0 elsez.

z=1.23-0j
# If the imaginary part is 0, only the real part is displayed.
print(z.real if z.imag==0 elsez)

I edited this post based on @metropolis's comment and posted it as community wiki.I edited this post based on @metropolis's Comment and posted it as Community Wiki.


2022-09-30 14:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.