Strip Python Function - Guido Van Rossum
Strip Python Function - Guido Van Rossum

Strip function giúp loại bỏ ký tự hai đầu của chuỗi. Mặc định sẽ loại bỏ khoảng trắng ở hai đầu.

a = "    Hello, World!    "
print(a.strip()) # kết quả trả về sẽ là "Hello, World!"

Bạn cũng có thể truyền vào một SET cần loại bỏ như sau:

txt = ",,,,,rrttgg.....banana....rrr"
x = txt.strip(",.grt")
print(x) # Bạn đoán xem
Last modified: September 8, 2023

Author

Comments

Write a Reply or Comment

Your email address will not be published.