Sven Fridge
Sven Fridge

Reputation: 75

How to print brackets in python

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... -.-

Upvotes: 3

Views: 29912

Answers (4)

fgb
fgb

Reputation: 3119

Try this:

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

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

Upvotes: 0

aldeb
aldeb

Reputation: 6828

Using string formatting:

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

Upvotes: 2

Vorticity
Vorticity

Reputation: 4928

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

Upvotes: 1

Danial Tz
Danial Tz

Reputation: 1984

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

Upvotes: 2

Related Questions