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

วิธีลบ Trailing Whitespace ของ String ใน Python

ใช้ rstrip() default ตัด whitespace ท้าย

ตัวอย่าง

>> '  Hello  '.rstrip()
'  Hello'
>>> 'Ninja Turtles the movie   '.rstrip()
'Ninja Turtles the movie'

ระบุ chars ตัดได้: rstrip('chars')