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

Asked 1 months ago, Updated 1 months ago, 1 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.

# 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

© 2022 OneMinuteCode. All rights reserved.