2018年1月11日 星期四

Python: Add leading zeroes to a string

Python: Add leading zeroes to a string

Python Basic: Exercise-129 with Solution

Write a Python program to add leading zeroes to a string.
Sample Solution:-
str1='122.22'
print("Original String: ",str1)
str1 = str1.ljust(8, '0')
print(str1)
str1 = str1.rjust(10, '0')
print(str1)
# ljust , rjust 

========== RESTART: F:/Python_APSC/py-ex-basic-129.py ===========
Original String:  122.22
122.2200
00122.2200
>>> 

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...