DEV Community

Cover image for String in Python
Islamali Akhmadjanov
Islamali Akhmadjanov

Posted on • Edited on

1

String in Python

STRING (matn) —Pythondagi eng mashxur ma'lumot turlaridan biri. Avvalgi darsda ko'rganimizdek, o'zgaruvchiga matn yuklash uchun matn qo'shtirnoq (" ") yoki birtirnoq (' ') ichida yozilishi kerak.

ism = "Abdumajid"
familiya = 'Akhmadjanov'

Enter fullscreen mode Exit fullscreen mode

STRING USTIDA AMALLAR
Matnlarni qo'shish operatori (+)
Matnlarni qo'shish uchun + operatoridan foydalanmiz:

ism = 'Diyorbek'
print("Mening ismim " + ism)
Enter fullscreen mode Exit fullscreen mode

Natija: Mening ismim Diyorbek

ism = 'Islam'
familiya = 'Akhmadjanov'
print(ism + familiya)
Enter fullscreen mode Exit fullscreen mode

Natija: Islam Akhmadjanov

f-string
Ikki (va undan ko'p) matn ko'rinishidagi o'zgaruvchilarni birlashtirish uchun f-string usulidan f"{matn1} {matn2}" ham foydalansak bo'ladi:

ism = "Javohir"
familiya = 'Ravshanov'
ism_sharif = f"{ism} {familiya}"
print(ism_sharif)
Enter fullscreen mode Exit fullscreen mode

Natija: Javohir Ravshanov

Bu usul yordamida uzun matnlarni ham yasash mumkin:

ism = "James"
familiya = 'Bond'
print(f"Salom, mening ismim {familiya}. {ism} {familiya}!")
Enter fullscreen mode Exit fullscreen mode

Natija: Salom, mening ismim Bond. James Bond!

Mahsus belgilar
Matnga bo'shliq qo'shish uchun \t belgisidan, yangi qatordan boshlash uchun \n belgisidan foydalanamiz:

print('Hello World!')
print('Hello \tWorld!')
print('Hello \nWorld!')
Enter fullscreen mode Exit fullscreen mode

Natija:
Hello World!
Hello World!
Hello
World!

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay