Creating Strings

Creating Strings

Pythonలో text లేదా characters సమూహాన్ని String అంటాము. Stringను create చేయడానికి textను quotes మధ్యలో రాసి, ఒక variableలో store చేస్తాము.

ఉదాహరణకు, name = "Anu"లో "Anu" ఒక String. ఆ Stringను name అనే variableలో భద్రపరుస్తాము.

Strings ఎందుకు ఉపయోగిస్తాము?

  • వ్యక్తి పేరు store చేయడానికి
  • నగరం లేదా దేశం పేరు store చేయడానికి
  • Messages మరియు sentences store చేయడానికి
  • Website లేదా applicationలో text చూపించడానికి

String ఎలా create చేయాలి?

ముందుగా variable name రాయాలి. తర్వాత = గుర్తు పెట్టాలి. చివరగా textను quotes మధ్యలో రాయాలి. Python ఆ textను Stringగా గుర్తిస్తుంది.

Simple Explanation

String create చేయడం అంటే textను quotes మధ్యలో రాసి variableలో store చేయడం.

ఉదాహరణ: city = "Hyderabad"

ఇక్కడ city variable. "Hyderabad" String value. తర్వాత city variableను ఉపయోగించి ఆ textను print చేయవచ్చు.

Stringలో letters, spaces, numbers మరియు కొన్ని symbols ఉండవచ్చు. కానీ అవి quotes మధ్యలో ఉంటే అవి textగా పరిగణించబడతాయి.

Real-Life Example

ఒక school formలో విద్యార్థి పేరు మరియు course పేరు రాస్తామని అనుకోండి. పేరు, course రెండూ text కాబట్టి వాటిని Stringsగా store చేయవచ్చు.

ఉదాహరణకు, విద్యార్థి పేరు "Anu", course పేరు "Python". వీటిని variablesలో store చేసి అవసరమైనప్పుడు display చేయవచ్చు.

Code Examples

రెండు Strings create చేసి print చేయడం

name = "Anu"
course = "Python"
print(name)
print(course)

ఈ codeలో రెండు text valuesను Stringsగా create చేసి variablesలో store చేశాము. తర్వాత print() ఉపయోగించి వాటిని outputగా చూపించాము.

Anu
Python

Line-by-Line Explanation

name = “Anu”

ఈ lineలో "Anu" అనే textను Stringగా create చేసి name variableలో store చేస్తాము. Python ఈ lineను execute చేసినప్పుడు nameలో ఆ String value ఉంటుంది.

course = “Python”

ఈ lineలో "Python" అనే textను Stringగా create చేసి course variableలో store చేస్తాము. ఇప్పుడు courseలో Python అనే value ఉంటుంది.

print(name)

ఈ line name variableలో ఉన్న Stringను screenపై చూపిస్తుంది. Outputలో Anu కనిపిస్తుంది.

print(course)

ఈ line course variableలో ఉన్న Stringను screenపై చూపిస్తుంది. Outputలో Python కనిపిస్తుంది.

Try It

Try this Python code:

Example

person_name = "Ravi"
city_name = "Chennai"
print(person_name)
print(city_name)

Try It Yourself »

Practice

Practice: మీకు ఇష్టమైన food పేరు మరియు దాని typeను రెండు వేర్వేరు String variablesలో store చేసి, వాటిని print చేయండి.

Hint: ఉదాహరణకు food_name = "Pizza" లాగా textను quotes మధ్యలో రాయండి.

Practice: ఒక book పేరు మరియు author పేరు రెండు Stringsగా create చేసి outputలో చూపించండి.

Hint: రెండు variables create చేసి ప్రతి variableను వేర్వేరు print() linesలో ఉపయోగించండి.

Common Mistakes

Textను quotes లేకుండా రాయడం: name = Anu

Textను quotes మధ్యలో రాయాలి: name = "Anu". Quotes లేకుండా రాస్తే Python దాన్ని textగా గుర్తించకపోవచ్చు.

Variable name మరియు String valueను గందరగోళపరచడం: "name" = "Anu"

Variable name quotes లేకుండా ఉండాలి. సరైన విధానం: name = "Anu".

Stringను create చేసిన తర్వాత variableను print చేయకపోవడం.

String valueను చూడటానికి print(variable_name) ఉపయోగించాలి.

Quotes సరిగ్గా close చేయకపోవడం: city = "Delhi

String ప్రారంభంలో మరియు చివరలో quotes ఉండాలి: city = "Delhi".

Interview Questions

Pythonలో String ఎలా create చేస్తారు?

Answer: Textను quotes మధ్యలో రాసి variableలో assign చేయడం ద్వారా String create చేస్తారు. ఉదాహరణ: name = "Ravi".

Stringను variableలో ఎందుకు store చేస్తారు?

Answer: Textను తర్వాత మళ్లీ ఉపయోగించడానికి, print చేయడానికి లేదా programలో reference చేయడానికి Stringను variableలో store చేస్తారు.

ఈ codeలో String value ఏది? city = "Delhi"

Answer: "Delhi" String value. city variable name.

Exam Questions

Pythonలో String create చేయడానికి ఏది అవసరం?

Answer:

Textను quotes మధ్యలో రాయాలి. ఉదాహరణ: message = "Hello".

క్రింది code output ఏమిటి? language = "Python"
print(language)

Answer:

Output: Python

క్రింది వాటిలో సరైన String creation ఏది?
A) name = Anu
B) name = "Anu"

Answer:

సరైన సమాధానం B: name = "Anu". ఎందుకంటే text quotes మధ్యలో ఉంది.

Quick Revision

  • String అనేది text data.
  • String create చేయడానికి textను quotes మధ్యలో రాయాలి.
  • Stringను variableలో store చేయడానికి assignment operator = ఉపయోగిస్తాము.
  • ఉదాహరణ: name = "Anu".
  • String valueను చూపించడానికి print() ఉపయోగించవచ్చు.

Test Your Knowledge

Take a short quiz based on this lesson.

10 Questions • Results
Scroll to Top