How to print WITHOUT New line in Python using print method?
Hello,
I am a newbie in Python and I have a list:
ourPositions = ["FrontEnd", "BackEnd", "Designer", "Transfer Html", "Project Onwer"]
And I want to print the values inside the list using for-loop. So here I use of print() to display the values inside the list as shown in the example below:
ourPositions = ["FrontEnd", "BackEnd", "Designer", "Transfer Html", "Project Onwer"]
for i in ourPositions:
print(i)
And output:
FrontEnd
BackEnd
Designer
Transfer Html
Project Onwer
You can see they break new line for each item of list. I want to print all of them in a single line and separate by a comma (,). How can I do it?
Thankyou for any suggestions.
-
C1
Chaouch Nesrine Feb 10 2022
I think the best way, you no need to loop with. You can use
join()
method to help convert a list to a string with commas separate.You can see an example below:
ourPositions = ["FrontEnd", "BackEnd", "Designer", "Transfer Html", "Project Onwer"] stringPos = ", ".join(ourPositions) print(stringPos)
And my output:
FrontEnd, BackEnd, Designer, Transfer Html, Project Onwer
You can see it is so easy.
-
S0
Sree Vs Feb 10 2022
It's so easy, you can change
print(i)
toprint(i, end=",")
ourPositions = ["FrontEnd", "BackEnd", "Designer", "Transfer Html", "Project Onwer"] for i in ourPositions: print(i, end=",")
#Output
FrontEnd,BackEnd,Designer,Transfer Html,Project Onwer,
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.