NeoAstro
NeoAstro

Reputation: 17

Python: What am I doing wrong

I am learning how to code. This is my code:

race = 'Daytona 500' 
print( race , 'is' + type( race )  )

And the error is:

print( race , 'is' + type( race ) )
TypeError: must be str, not type

Please help, what am I doing wrong

Upvotes: 0

Views: 150

Answers (2)

Carlo 1585
Carlo 1585

Reputation: 1477

you can use as well:

print( race + ' is '+ str(type(race)))

Upvotes: 2

Chanda Korat
Chanda Korat

Reputation: 2561

Better to use format here

race = 'Daytona 500' 
print( race + ' is '+'{}'.format(type(race)))

It will print Daytona 500 is <type 'str'>

Upvotes: 3

Related Questions