Ravindra Bagale · Data Scienceसर्व coursesया course चे lessonsशोधाEnglish

Data Science · मराठी आवृत्ती · Python basics

P3.1 Python मध्ये Strings कशा तयार करायच्या आणि जोडायच्या?

By Ravindra Bagale

हे का शिकायचं?

Reports मध्ये नावं, labels आणि messages बनवताना text जोडावा लागतो.

हे काय आहे?

String म्हणजे quotes मधला text. + ने strings जोडतात, * ने repeat करतात आणि len() ने लांबी कळते.

कसं करायचं?

Step 1. Text quotes मध्ये लिहा.

Step 2. + ने जोडा.

Step 3. len() ने लांबी तपासा.

उदाहरणं: copy करा आणि चालवा

उदाहरण A: दोन strings तयार करा

हा code चालवा:

name = "Priya"
city = "Nagpur"
print(name)
print(city)

तुम्हाला दिसणारा output:

Priya
Nagpur

याचा अर्थ: Single किंवा double quotes दोन्ही चालतात.

उदाहरण B: Strings जोडा

हा code चालवा:

name = "Priya"
city = "Nagpur"
label = name + " from " + city
print(label)

तुम्हाला दिसणारा output:

Priya from Nagpur

याचा अर्थ: + ने text जोडला. मधली space आपणच टाकावी लागते.

उदाहरण C: लांबी आणि repeat

हा code चालवा:

code = "SKU-1042"
print(len(code))
print("-" * 20)

तुम्हाला दिसणारा output:

8
--------------------

याचा अर्थ: len() अक्षरांची संख्या देतो आणि * text repeat करतो.