Printing some data along with some string@python

How to concatenate String and boolean in python?I am not able to do so?

That doesn’t make sense to do. Maybe you mean that you want to concatenate a string with a string representation of a bool - ie you want to concatenate two strings.


Hello, @ahmadarefeen08570876! Welcome to the forum.

Here are a couple of examples of what I believe you are attempting:

ans = True
print('You answered:', ans, 'The correct answer was:', not ans)
print('Your answer was {}.'.format('correct' if ans else 'not correct'))


You answered: True The correct answer was: False
Your answer was correct.

There are several other ways to accomplish the same task.

Happy Coding!

1 Like