طريقة Python String rjust ()
مثال
عرض نسخة مبررة بطول 20 حرفًا من كلمة "موزة":
txt = "banana"
x = txt.rjust(20)
print(x, "is my
favorite fruit.")
ملاحظة: في النتيجة ، يوجد في الواقع 14 مسافة بيضاء على يسار كلمة موز.
التعريف والاستخدام
ستعمل rjust()
الطريقة على محاذاة السلسلة بشكل صحيح ، باستخدام حرف محدد (المسافة الافتراضية) كحرف تعبئة.
بناء الجملة
string.rjust(length, character)
قيمه المعامل
Parameter | Description |
---|---|
length | Required. The length of the returned string |
character | Optional. A character to fill the missing space (to the left of the string). Default is " " (space). |
مزيد من الأمثلة
مثال
استخدام الحرف "O" كحرف مساحة متروكة:
txt = "banana"
x = txt.rjust(20, "O")
print(x)