+ 1

Python Type Conversion

Why a space is added when below tuple is covered to string? shiv = (11,5,7,2,2) shiv = str(shiv) print (shiv) print (s[4])

21st Mar 2020, 2:11 PM
Rini
Rini - avatar
5 Answers
+ 2
Ok, but why is space added? The original tuple doesn't have any.
22nd Mar 2020, 7:08 AM
Rini
Rini - avatar
+ 1
Rini Even before converting it to string, it would have spaces. You can remove the spaces after converting into by, shiv = shiv.replace(" ", "")
21st Mar 2020, 2:17 PM
maf
maf - avatar
+ 1
Rini original tuple HAS spaces after commas.
22nd Mar 2020, 7:13 AM
maf
maf - avatar
+ 1
Yes, you are right it has. I never paid attention to the output format. I couldn't find the exact reason why space is added after comma, but from what I read it is for better readability. Thanks!
22nd Mar 2020, 10:34 AM
Rini
Rini - avatar
0
@Rini lol no problem :)
22nd Mar 2020, 10:35 AM
maf
maf - avatar