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))

16th Mar 2019, 3:59 PM
Dave Merrique
Dave Merrique - avatar
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.
16th Mar 2019, 4:28 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 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"
16th Mar 2019, 4:45 PM
Maninder $ingh
Maninder $ingh - avatar
0
thank you!!!...it makes sense now.
16th Mar 2019, 4:36 PM
Dave Merrique
Dave Merrique - avatar