DEV Community

Cover image for String in Python
islomAli99
islomAli99

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

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

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

Okay