avoiding brackets in print command

24 views
Skip to first unread message

Senthil Ranga

unread,
Apr 24, 2020, 12:35:34 AM4/24/20
to spyder
hi friends

i am very new to python whenever running print command, its shows with in bracket 

i.e ...
continue? (0/1)1
('token number', 2, 'may please come in')

continue? (0/1)1
('token number', 3, 'may please come in')

how can avoid brackets? (look the attachment)

pl help me..

thanks
Senthil 
format.png

Jim Lareau

unread,
Apr 24, 2020, 6:31:11 PM4/24/20
to spyder
I noticed that you are using python 2.7 but using the python 3 form of the print command... Could this be your issue?

Senthil Ranga

unread,
Apr 25, 2020, 7:33:48 PM4/25/20
to spyder
yes  of course  thanks friends

Philip Yip

unread,
Apr 26, 2020, 8:34:24 PM4/26/20
to spyder
You have created a tuple. Removing the complications of the print command lets look at what you've typed:

x='token number', 2, 'may please come in'

x[0]=token number'
x[1]=2
x[2]='may please come in

Since you haven't enclosed the elements a tuple is created and the () are automatically added.

Therefore your output is a tuple:

x=('token number', 2, 'may please come in')

Note that each element in your tuple has a different type (you'll see this if you look at the items on the variable explorer).

x[0] is a str
x[1] is an int
x[2] is a str

To concatenate you need to have all three parts being str and you use the + not the , to concatenate str.

x='token number'+str(2)+'may please come in'

Will concatenate the three strings. However you may also want to include spaces

x='token number '+str(2)+' may please come in'

Also if you are just getting started on Python is there any particular reason your using Python 2.x and presumably an older version of Anaconda and Spyder.
Python 2 reached end of life in January 2020 and also Windows 7 reached end of life in April 2020.

Although Windows 7 is at end of life Anaconda 2020-02 states that Windows 7 is supported but is going to be the last version of Anaconda to run on Windows 7.

2.PNG

Reply all
Reply to author
Forward
0 new messages