0
Can anyone explain
Hi all, I have been doing a lot of challenges could anyone make sense of this for me. a = "solo" print(a.zfill(6))
3 Answers
+ 1
It pads the string left with zeros. The length of string "a" is 4 so it's padded left with 6-4 zeros => "00solo".
You can find more info here: https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/string_zfill.htm
Hope it helps you.
+ 1
zfill function help us to fill the zeros in start of the string.
zfill(x)--> here x refer to how many zeros you want to fill.
Output=x-len(string)
Now,
a='solo'
print(a.zfill(6))
Here you want to fill 6 zeros in front of the (a)string and output will be 6-4=2 means total 2 zeros will be add because 4 is length of the a variable and output =x-len(string)
Output="00solo"
0
thank you!!!...it makes sense now.