Reputation: 3218
I am new in python3
(and python
, all together), and still reading the docs.
So, I am facing many small and silly problems.
Currently, I am facing a problem of printing a list
in a line.
If I print
it inside a for loop
,
for n in range(1,4):
print(self.lstCord[self.q][n])
the lstCord are of type string
.
expectedly, I am getting:
0
1
2
But if I print as
print(self.lstCord[self.q][1], self.lstCord[self.q][2], self.lstCord[self.q][3])
its printing as:
('1', '2', '3')
while I am looking for the output as:
1 2 3
i.e. without (
,)
, '
and ,
and in the same line.
How can i get this?
Upvotes: 0
Views: 79
Reputation: 1458
In Python3 print has become a function. That means you can do this
for n in range(1,4):
print(self.lstCord[self.q][n], end=" ")
.. which will end the printing of each item with a space.
Upvotes: 1
Reputation: 1084
You can just add a ',' at the end of the print line in the first example:
for n in range(1,4):
print(self.lstCord[self.q][n]),
this will print all the list in the same line.
In the second example you get () because you are printing a tuple. If you remove the () you would get the same result.
Upvotes: 0