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

3
  • 1
    Try explicit conversion: print('Foos present:' + str(foo), 'Fees present:' + str(fee)) Commented Jan 20, 2017 at 10:07
  • That worked. Thanks. Commented Jan 20, 2017 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. Commented Jan 20, 2017 at 10:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.