Important Notice:

Creating Strings

Creating Strings

1 views 2 min read

Creating Strings (स्ट्रिंग बनाना) :-

Creating Strings (स्ट्रिंग बनाना) का अर्थ है Python में किसी Text (पाठ), Character (अक्षर), Word (शब्द) या Sentence (वाक्य) को String के रूप में बनाना और उसे किसी Variable में Store करना।

Python में String बनाने के लिए Characters को Quotes (उद्धरण चिह्नों) के अंदर लिखा जाता है। Python चार प्रकार के Quotes का समर्थन करता है:

  • Single Quotes (' ')
  • Double Quotes (" ")
  • Triple Single Quotes (''' ''')
  • Triple Double Quotes (""" """)

English

Creating Strings means creating a String object in Python to store text, characters, words, or sentences.

In Python, a String is created by enclosing text within quotation marks (quotes). Python supports four types of quotes:

  • Single Quotes (' ')
  • Double Quotes (" ")
  • Triple Single Quotes (''' ''')
  • Triple Double Quotes (""" """)

Syntax (सिंटैक्स) -

variable_name = "String"

Methods of Creating Strings (स्ट्रिंग बनाने के तरीके)

Python में String निम्नलिखित तरीकों से बनाई जा सकती है:

  1. Using Single Quotes (' ')
  2. Using Double Quotes (" ")
  3. Using Triple Single Quotes (''' ''')
  4. Using Triple Double Quotes (""" """)
  5. Using the str() Constructor

1. Creating String Using Single Quotes (' ') :-

Single Quotes का उपयोग सामान्य (Simple) String बनाने के लिए किया जाता है।

Single quotes are commonly used to create simple strings.

Example-

name = 'Python'

print(name)
print(type(name))
 
2. Creating String Using Double Quotes (" ") :-

Double Quotes भी Single Quotes की तरह कार्य करते हैं। इनका उपयोग विशेष रूप से तब किया जाता है जब String में Apostrophe (') हो।

Double quotes work the same as single quotes. They are useful when the string contains an apostrophe (').

Example-
language = "Python Programming"

print(language)
 
3. Creating String Using Triple Single Quotes (''' ''') :-

Triple Single Quotes का उपयोग Multi-line String (एक से अधिक पंक्तियों वाली स्ट्रिंग) लिखने के लिए किया जाता है।

Triple single quotes are used to create multi-line strings.

Example-
text = '''Python
is
Easy'''

print(text)
 
Output -
Python
is
Easy
4. Creating String Using Triple Double Quotes (""" """) :-

Triple Double Quotes भी Multi-line String बनाने के लिए उपयोग किए जाते हैं।

Triple double quotes are also used to create multi-line strings.

Example -
text = """Welcome
to
Python"""
print(text)
Output -
Welcome
to
Python
 
5. Creating String Using str() Constructor :-

Python में str() Function का उपयोग किसी Value को String में बदलने या नई String बनाने के लिए किया जाता है।

The str() function is used to create a string or convert another data type into a string.

Example 1 -
num = str(100)

print(num)
print(type(num))
Output:-
100
<class 'str'>
 
 

Related Notes