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)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay