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

วิธีลบ Leading Whitespace ใน String Python

ใช้ lstrip() ตัด whitespace, newline, tab นำหน้า

>> '    hello world!'.lstrip()
'hello world!'

ใช้ strip() ตัดทั้งนำและท้าย

>> '    hello world!    '.strip()
'hello world!'