On 04/30/2012 05:50 AM, viral shah wrote: > Hi > > I'm new in the learning of python > > I want to make simple code for two variable addition > > Please help me in the following code > > *x = 12 > print x > y =20 > print y > z = x+y > print 'Addition of above two numbers are : ' + int.z > * > when I run this same I got an error message : > > *AttributeError: type object 'int' has no attribute 'z' > > Please help me to solve the same error > >
Welcome to Python tutor. Normally, the print statement accepts a list of items, separated by commas. Each item is implicitly converted to a string, and the results are sent to standard out, with a space between each item. So the most straightforward way to print z would be something like: print 'Addition of above two numbers are:', z Now, sometimes you want to combine two strings yourself, so you might use: print 'Addition of above two numbers are:' + str(z) Here we are using the str type as a conversion function. Note that we used parentheses, not the dot operator. And notice that since print only gets one item, it does not add a space. -- DaveA _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor