[Tutor] Python Variable Addition

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Apr 30 20:27:15 CEST 2012

On 30/04/2012 18:36, Alan Gauld wrote:
> On 30/04/12 11:00, Kapil Shukla कपिल शुक्‍ला wrote:
>> Viral
>> You should be doing this
>> "Addition of two numbers is" + str(x+y)
> There is no need for str() since print implicitly calls string to
> convert objects to string format. Also the addition is not needed since
> print takes a comma separated list of arguments. So it would normally be:
> print 'Addition of above two numbers are : ', z

Except that you'll get two spaces after the colon :)

>> + operator works on same datatypes and
> Using addition on strings is quite expensive and there are usually
> better ways to do the same job.
>> int being one of the built in objects in python does not have a method z
> This however is true(ish - int is a type not strictly an object, except
> that everything in Python is an object, including types! :-) and it is
> the source of the original error message.


Mark Lawrence.

More information about the Tutor mailing list