python> I want to display the number 8 as 008> print "{0: 0> 3}". format (8) or "{value: 0> 3}". format (value = 8) or "% 03d"% 8 Or format (8, "03d") or str (8) .zfill (3) or (Python 3.6 or later) f "{8: 0> 3}"

reference http://python.civic-apps.com/string-format-function/

151125d.py


print "{0:0>3}".format(8)

Run


[toLearn]$ python 151125d.py 
008

Matters taught

@ shiracamus's Comment taught me various ways of writing.

I added it to the title so that it can be found by searching.

Recommended Posts

python> I want to display the number 8 as 008> print "{0: 0> 3}". format (8) or "{value: 0> 3}". format (value = 8) or "% 03d"% 8 Or format (8, "03d") or str (8) .zfill (3) or (Python 3.6 or later) f "{8: 0> 3}"
I want to display the progress in Python!
I want to initialize if the value is empty (python)
I want to display the progress bar
[Python] How to change the date format (display format)
I want to get the file name, line number, and function name in Python 3.4
I want to write in Python! (1) Code format check
I want to inherit to the back with python dataclass
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
maya Python I want to fix the baked animation again.
[Python] I want to use the -h option with argparse
I want to know the features of Python and pip
I want to map the EDINET code and securities number
I want to know the weather with LINE bot feat.Heroku + Python
python> Display 3 decimals in ".3f, .3f, .3f" format / Get 3 coordinate values in the range [-1: 1]
I want to output the beginning of the next month with Python
I want to run the Python GUI when starting Raspberry Pi
I tried to display the video playback time (OpenCV: Python version)
I want to use both key and value of Python iterator
I wanted to solve the ABC164 A ~ D problem with Python
Solve the smallest value in Python (equivalent to paiza rank D)
I want to display the number of num_boost_rounds when early_stopping is applied using XGBoost callback (not achieved)
I want to debug with Python
[Python memo] I want to get a 2-digit hexadecimal number from a decimal number
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
(Python) I tried to analyze 1 million hands ~ I tried to estimate the number of AA ~
I tried to display the altitude value of DTM in a graph
I want to format and check Python code to my liking on VS Code
Python: I want to measure the processing time of a function neatly