Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python format 2 digits

number = 1

# In Python 2 (and Python 3) you can do:
print("%02d" % (number,))
# Basically % is like printf or sprintf (see docs).

# For Python 3.+, the same behavior can also be achieved with format:
print("{:02d}".format(number))

# For Python 3.6+ the same behavior can be achieved with f-strings:
print(f"{number:02d}")
Comment

format number of digits python

# credit to Stack Overflow user in source link
# x is a floating point number
# a is the total width of the field being printed, lefted-padded by spaces.
# b is the number of digits after the decimal point

print("{:a.bf}".format(x))
Comment

PREVIOUS NEXT
Code Example
Python :: purge command discord.py 
Python :: create an array from 1 to n python 
Python :: python get user home directory 
Python :: tensorflow load h5 model 
Python :: python pyodbc install 
Python :: get number of missing values dataframe 
Python :: print all keys having same value 
Python :: np array n same values 
Python :: set cuda visible devices python 
Python :: ban discord.py 
Python :: daphne heroku 
Python :: datetime not defined python 
Python :: pytest skip 
Python :: python infinite value 
Python :: how to rewrite minute in datetime python 
Python :: django bootstrap 5 
Python :: django-admin command not found 
Python :: opencv get area of contour 
Python :: how to get continuous mouse position with pyautogui in python 
Python :: How to convert an integer number into words in python? 
Python :: python get current number of threads 
Python :: matplotlib remove ticks and lines 
Python :: n random numbers python 
Python :: auth proxy python 
Python :: remove comma from string python column 
Python :: rename multiple pandas columns with list 
Python :: python generate table 
Python :: count how many duplicates python pandas 
Python :: how to multi random pick from list python 
Python :: edge driver selenium python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =