0

I know that in Python 3, print is now a function.

However, I have two variables that I wish to include in a print function.

foo = 5

fee = 3

The following gives an error:

print('Foos present:' + foo, 'Fees present:' + fee)

TypeError: Can't convert 'float' object to str implicitly

cbll
  • 6,499
  • 26
  • 74
  • 117
  • 1
    Try explicit conversion: print('Foos present:' + str(foo), 'Fees present:' + str(fee)) – Oblomov Jan 20 '17 at 10:07
  • That worked. Thanks. – cbll Jan 20 '17 at 10:11
  • The real solution here isn't to use `str` to force your variable values into strings. It's to remove the `+` signs and replace them with commas. `print('A' + B)` is trying to print the **sum** of A and B. Using `print('A', B)` means print the text A then the variable B. – CJC Jan 20 '17 at 10:37

0 Answers0