2 Replies - 5381 Views - Last Post: 07 March 2012 - 03:28 PM Rate Topic: -----

#1 dag72   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 205
  • Joined: 02-March 11

How o concatenate str and int object

Posted 07 March 2012 - 02:40 PM

Hi i am new to python and would like to print out the following line of code in a cash reg program... but when i concatenate like this as i would in Java the following message occurred. 'cannot concatenate 'str' and 'float' objects. How could i rectify this please

print ("Your change is: "+change)

print ("You paid: "+amountPaid)


Is This A Good Question/Topic? 0
  • +

Replies To: How o concatenate str and int object

#2 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: How o concatenate str and int object

Posted 07 March 2012 - 02:51 PM

Well, you can either cast it to a string using str(), or you can use string formatting.
Was This Post Helpful? 1
  • +
  • -

#3 dag72   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 205
  • Joined: 02-March 11

Re: How o concatenate str and int object

Posted 07 March 2012 - 03:28 PM

Many thanks for your speedy reply, I rectify this using the following

print 'your change is %d' %change

print 'you paid %d' %amountPaid

This post has been edited by dag72: 07 March 2012 - 03:29 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1