Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีสร้าง Space-padded String Right-justified ใน Python

ใช้ rjust(width[, fillchar]) default fillchar คือ space

ตัวอย่าง

>> '15'.rjust(10)
'        15'
>>> 'Yes'.rjust(2)
'Yes'
>>> 'raj'.rjust(12)
'         raj'

ถ้า width น้อยกว่าความยาวสตริง จะคืนสตริงเดิม