Home > Enterprise >  can only concatenate str (not "complex") to str
can only concatenate str (not "complex") to str

Time:08-08

Why I am getting this error (TypeError: can only concatenate str (not "complex") to str? I am not doing any kind of concatenation in my code. I am confused, please help me.

print("%d" % 5 8j)

CodePudding user response:

You need parenthesis

print("%s" % (5 8j))

Otherwise, it's understood as

print(("%s" % 5) 8j)

Incidentally, there is no point in using %d instead of %s, as it's just less general.

CodePudding user response:

To convert a complex number to string you have to do that

print( str(5 8j) )
  • Related