Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ID number zero python

>>> f'{5:04}'
'0005'

>>> f'{5:04}'
'0005'

#This uses the string formatting minilanguage:
>>> five = 5
>>> f'{five:04}'
'0005'

#The first zero means the fill, the 4 means to which width:
>>> minimum_width = 4
>>> filler = "0" # could also be just 0
>>> f'{five:{filler}{minimum_width}}'
'0005'

#Next using the builtin format function:
>>> format(5, "04")
'0005'
>>> format(55, "04") 
'0055'
>>> format(355, "04")
'0355'

#Also, the string format method with the minilanguage:
>>> '{0:04}'.format(5)
'0005'

#Again, the specification comes after the :, and the 0 means fill with zeros and the 4 means a width of four.
#Finally, the str.zfill method is custom made for this, and probably the fastest way to do it:
>>> str(5).zfill(4)
'0005'
Comment

PREVIOUS NEXT
Code Example
Python :: load text file line in listbox python tkinter site:stackoverflow.com 
Python :: Checking Availability of user inputted File name 
Python :: flask decorator causes views to be named the same thing 
Python :: medium seaaborn mathplot diesign styles 
Python :: empaquetado y manejo dependencias en python 
Python :: linux pyspark select java version 
Python :: python gmail 
Python :: sys executable juypter is incorrect visual code 
Python :: derivative of multivariable function pytorch 
Python :: flatten a list of lists python 
Shell :: linux get cpu frequency 
Shell :: remove angular cli 
Shell :: git store credential 
Shell :: refusing to merge unrelated histories 
Shell :: list process using port 
Shell :: error gyp ERR! stack Error: not found: make 
Shell :: git config username and password global 
Shell :: chrome update ubuntu 20.04 
Shell :: ubuntu apt-get update without input 
Shell :: install tkinter in ubuntu 
Shell :: undo commits git 
Shell :: sudo: aptitude: command not found 
Shell :: remove heroku remote 
Shell :: uninstall apache2 ubuntu 20.04 
Shell :: install putty on ubuntu 
Shell :: restart php nginx mac 
Shell :: reload supervisor 
Shell :: update git version in ubuntu 
Shell :: how to install react router dom with typescript 
Shell :: grafana cli restart 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =