3

i want to print "(" in python

print "(" + var + ")"

but it says:

TypeError: coercing to Unicode: need string or buffer, NoneType found

can somebody help me? that cant be too hard... -.-

3
  • 2
    why don't you do: print "(%s)" % var?
    – Laur Ivan
    Apr 29, 2013 at 20:31
  • 1
    var is None, you should do what equinoxel said
    – cmd
    Apr 29, 2013 at 20:34
  • these are NOT brackets. these are parentheses. VERY important distinction.
    – WhiteRau
    Nov 25, 2021 at 5:21

4 Answers 4

2

Using string formatting:

foo = 'Hello'
print('({})'.format(foo))
2

maybe a simple print "(" + str(var) + ")"?

1

it appears that var is None in what you provided. Everything is correct, but var does not contain a string.

0

Try this:

var = 'Hello World!'
print('(' + var + ')')

Also, your code works well on Python 2.7.4, so long as you pre-define var.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.