1. 程式人生 > >#Python3中填充指定寬度的左對齊字串ljust()

#Python3中填充指定寬度的左對齊字串ljust()

9.(str).ljust()
ljust(width.fillchar)
left縮寫成ljust的l
返回一個指定寬度的左對齊字串,fillchar為填充字元
不寫fillchar 則預設空格
ljust() L 的小寫

str2 = "Good job"
print(str2.ljust(40) )			#(輸出)Good job    
print(str2.ljust(40,"*") )		#(輸出)Good job********************************
								#從字元後面移植填充到指寬度
print(str2.ljust(40),"*" )		#(
輸出)Good job * #在寬度的最後填充一個字元結尾