Python String rstrip()เมธอด
ตัวอย่าง
ลบช่องว่างสีขาวที่ส่วนท้ายของสตริง:
txt = " banana "
x =
txt.rstrip()
print("of all fruits", x, "is my favorite")
ความหมายและการใช้งาน
วิธี การrstrip()
ลบอักขระต่อท้าย (อักขระที่ส่วนท้ายของสตริง) ช่องว่างคืออักขระต่อท้ายเริ่มต้นที่จะลบ
ไวยากรณ์
string.rstrip(characters)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
characters | Optional. A set of characters to remove as trailing characters |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ลบอักขระต่อท้ายหากเป็นเครื่องหมายจุลภาค s q หรือ w:
txt = "banana,,,,,ssqqqww....."
x = txt.rstrip(",.qsw")
print(x)