DEV Community

Ozodbek Tohirov
Ozodbek Tohirov

Posted on

Python'da stiring method'lari

1. strip()

strip() usuli har qanday oldingi va keyingi bo'shliqlarni olib tashlaydi.

Leading string'ning boshini bildiradi, trailing oxiri'daligini bildiradi.

Sintaksisi

string.strip(characters)
Enter fullscreen mode Exit fullscreen mode

Qaysi belgilarni olib tashlanishi kerakligini belgilashingiz mumkin:

txt = ",,,,,rrttgg.....banana....rrr"

x = txt.strip(",.grt")

print(x)
Enter fullscreen mode Exit fullscreen mode

natija:

# banana
Enter fullscreen mode Exit fullscreen mode

, yo'qsa, barcha bo'shliqlar o'chiriladi:

txt = "     banana     "

x = txt.strip()
Enter fullscreen mode Exit fullscreen mode

natija:

# banana
Enter fullscreen mode Exit fullscreen mode

Top comments (0)