+ 1
how do we interpret this a.zfill()... Please explain!!
a='solo' print (a.zfill(6))
9 Antworten
+ 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
+ 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
+ 2
why dont you try on code playground?
+ 2
Thanks...Now I got it😊😊
+ 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))
+ 1
I tried and it shows the result as 00solo...
But I want to know the working of this function.
+ 1
Wow.. Thanks a lot for additional info.
+ 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))
0
So please help!!