+ 1

how do we interpret this a.zfill()... Please explain!!

a='solo' print (a.zfill(6))

16th May 2020, 7:25 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
9 Respuestas
+ 6
The zfill() method adds zeros to the front of the string until the total length of the string is equal to the integer passed to the method. https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_zfill.asp
16th May 2020, 7:43 PM
ChaoticDawg
ChaoticDawg - avatar
+ 4
A similar kind of fill can also be done with str.ljust(n), .rjust(n) or .center(n). The fill characters are spaces. This gives the following result compared to your test: 00solo solo solo solo
16th May 2020, 7:57 PM
Lothar
Lothar - avatar
+ 2
why dont you try on code playground?
16th May 2020, 7:41 PM
Oma Falk
Oma Falk - avatar
+ 2
Thanks...Now I got it😊😊
16th May 2020, 7:44 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
+ 2
You can see the available methods for any module in the playground or your CLI or IDLE etc by using the help() method. in the playground you can use; print(help(module_name)) to see what is available. You can also view a specific method of that module by using the name of the method. print(help(module_name.method_name)) For str print(help(str)) For the zfill() in the str module print(help(str.zfill))
16th May 2020, 8:07 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I tried and it shows the result as 00solo... But I want to know the working of this function.
16th May 2020, 7:42 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
+ 1
Wow.. Thanks a lot for additional info.
16th May 2020, 7:58 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
+ 1
string.zfill(len) a = "hello" b = "welcome to the jungle" c = "10.000" print(a.zfill(10)) print(b.zfill(10)) print(c.zfill(10))
17th May 2020, 4:26 AM
Humayun Ali Khan
Humayun Ali Khan - avatar
0
So please help!!
16th May 2020, 7:42 PM
Bhanu Tripathi
Bhanu Tripathi - avatar