Skip to content

Instantly share code, notes, and snippets.

@shoark7
Last active December 14, 2017 13:31
Show Gist options
  • Select an option

  • Save shoark7/ef8797fedb0e836f4a0778e4a4d552a6 to your computer and use it in GitHub Desktop.

Select an option

Save shoark7/ef8797fedb0e836f4a0778e4a4d552a6 to your computer and use it in GitHub Desktop.
Implement str.zfill method as function
def is_integer(n):
"""Return True if given n is integer.
Difference with isinstance(n, int) is that
this function returns True for string instance '123'.
"""
try:
int(n)
except:
return False
return True
def zero_fill(number, zeros=4):
"""Fill up zeros for the number if number is short"""
if not is_integer(number):
raise ValueError("Only Integer is accepted")
number = str(number)
if len(number) >= zeroes:
return
return '0' * (zeroes - len(number)) + number
@chaewonkong
Copy link
Copy Markdown

oh, you made a function to figure out whether the input is integer or not. Great Job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment