How to print list elements without space in python
I am doing a program that changes a number in base 10 to base 7, so i did this : Show
But if the number is 210 it prints 4 2 0 how do i get rid of the spaces
asked Nov 27, 2014 at 15:33
1 You can use join with list comprehension:
Also, don't use answered Nov 27, 2014 at 15:35
fredtantinifredtantini 14.9k8 gold badges46 silver badges54 bronze badges 2 In python 3 you can do like this :
Your output will be like this if input = 4 :
answered Nov 28, 2017 at 7:29
Vikas PeriyadathVikas Periyadath 2,9501 gold badge19 silver badges28 bronze badges Take a look at
Note two things
Also, it's handy to know that the construct you used:
is equivalent to (frankly a bit more efficient):
answered Nov 27, 2014 at 16:25
Convert the list to a string, and replace the white spaces.
answered Sep 17, 2019 at 0:45
bracoobracoo 1212 bronze badges You can use below code snippet for python3
Werner 1,8533 gold badges21 silver badges33 bronze badges
answered Feb 20, 2021 at 11:13
Use list_comprehension.
answered Nov 27, 2014 at 15:40
Avinash RajAvinash Raj 168k25 gold badges214 silver badges261 bronze badges 1 Doing the following worked for me in Python3
answered Aug 1, 2020 at 4:38 The print() function has an argument to specify the end character which by default is '\n'. Specifying the end character as '' and printing using a loop will do what you are looking for:
answered Jan 30, 2021 at 7:24
BinnyBinny 2331 gold badge2 silver badges7 bronze badges
It you print
If you print
Djib2011 6,4245 gold badges34 silver badges40 bronze badges answered Sep 22, 2018 at 12:23
How do I remove print space in Python?strip() Python String strip() function will remove leading and trailing whitespaces. If you want to remove only leading or trailing spaces, use lstrip() or rstrip() function instead.
How do I print numbers in Python without space in one line?The end=”” is used to print on same line without space. Keeping the doube quotes empty merge all the elements together in the same line.
How do I turn a string into a list without spaces?Use the list() class to split a string into a list of strings. Use a list comprehension to split a string into a list of integers.
How do you add a period without space in Python?print('The ratio of ' + str(number1) + ' + ' + str(number2) + ' is ' + str(ration12) + '. ') This way is probably the most basic way. It will join the strings without adding any characters in between them (e.g. no spaces in between unless you add them explicitly.)
|