473,513 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tab in a print statement in Python

1 New Member
I'm trying to print two variables together in one print statement in Python and getting TypeError: __add_nor_radd__ defined for these operands.

Any one has idea whats going on with this print statement?

Here is what i'm doing:

print var1+var2+var3 ---> all 3 var's are of integer type and when I execute this print statement prints only var1

print var1 +'\t'+ var2 ---> gives the above error mentioned above.
Sep 18 '11 #1
1 41427
bvdet
2,851 Recognized Expert Moderator Specialist
Use string formatting to print variables mixed with strings:
Expand|Select|Wrap|Line Numbers
  1. >>> var1 = 1
  2. >>> var2 = 2
  3. >>> var3 = 3
  4. >>> print var1+var2+var3
  5. 6
  6. >>> print var1+'\t'+var3
  7. Traceback (most recent call last):
  8.   File "<interactive input>", line 1, in ?
  9. TypeError: unsupported operand type(s) for +: 'int' and 'str'
  10. >>> print "%s\t%s" % (var1, var3)
  11. 1    3
  12. >>> print "%s %s %s" % (var1, var2, var3)
  13. 1 2 3
  14. >>> 
Sep 18 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5156
by: Michelle | last post by:
I have tried every variation of the "onchange" statement below without any actual reloading of the page. I am hoping that the PHP PRINT statement is constructed wrong, otherwise it is javaScript error an needs to be posted in the javaScript newsgroup. The FireFox javaScript Console reports the following message: Error: missing : in...
5
1874
by: vegetax | last post by:
How can i use cgi'like print statement in a multitreaded web framework? each thread has its own Servlet instance with request/response objects, sys.stdout = self.response(which is a file like object) wont work because all threads will set the same file object and it will be a concurrence mess. I am out of ideas here,so any hacks welcome =)
9
2296
by: François Pinard | last post by:
Hi, people. I hope someone would like to enlighten me. For any application handling Unicode internally, I'm usually careful at properly converting those Unicode strings into 8-bit strings before writing them out. However, this morning, I mistakenly forgot to do so before using one Unicode string (containing a non-ASCII character) as an...
6
2533
by: mirandacascade | last post by:
O/S: Win2K Vsn of Python: 2.4 Here is copy/paste from interactive window of pythonwin: >>> x = "Joe's desk" >>> y = 'Joe\x92s desk' >>> type(x) <type 'str'> >>> type(y)
3
11239
by: no_spam_for_gman | last post by:
Does db2 have the equivalent of a print statement like SQL server? I wanted to debug a stored procedure I wrote and wanted to output some of the values. I couldn't find it in documentation...The only thing that looked close was signal statement.
12
1902
by: jt2 | last post by:
Hello Perl Gurus! I'm quite a perl neophyte so I'm looking for help understanding why print doesn't print correctly. This may be a totally stupid error.... He is my program. What it is doing is parsing a file of comma seperated values and trying to extract the address field every time the clock field transitions from a zero to a one. ...
9
4912
by: TomEhrhorn | last post by:
I wrote some VBA code to create web pages (about 100 "identical" pages) with data from Access tables (data is static). Using "Print #1, ..." is a bit onerous but, with loops for repeated table rows was not too bad. However, I did find one problem for which I have no solution. In certain conditions (100% repeatable within a group of data but not...
0
889
by: Terry Reedy | last post by:
Robert Dailey wrote: Python version? Plafform? There may be a buffering issue. After the print, try import sys sys.stdout.flush()
2
2165
by: JRough | last post by:
I have this code that switches templates depending on if the user fills in a form with a request. The request asks for the $mark & $number. If that request gets input then it displays a list otherwise it re-displays the form request. The $template variable changes the value of which template is displayed. if($mark&&$num){ $mark = $mark =...
1
2424
by: josh wold | last post by:
Here is my problem. I'm using plink to ssh to devices and pull info off. I need to manipulate this data so that extra 0 at the end is making it difficult. C:\Python30>python PLINKSSHtest.py Enter your username: josh Password: plink -pw nowayjose -ssh nope@1.1.1.1 "show run | inc hostname" hostname net-R2 0 <------------MY ISSUE
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.