date = [2, 5, 2018]
text = "%s/%s/%s" % tuple(date)
print(text)
It gives result 2/5/2018
.How to convert it like 02/05/2018
date = [2, 5, 2018]
text = "%s/%s/%s" % tuple(date)
print(text)
It gives result 2/5/2018
.How to convert it like 02/05/2018
Use str.zfill(2)
to pad your date pieces with 2 leading zeros:
date = [2, 5, 2018]
text = "%s/%s/%s" % tuple([str(date_part).zfill(2) for date_part in date])
print(text) # Outputs: 02/05/2018
date = [2, 5, 2018]
text = "{:0>2}/{:0>2}/{}".format(*date)
print(text)
to learn more about using format
, read: https://pyformat.info/