Home » Tech Tutorials » Coding & Programming » Python » Python ఎలా పనిచేస్తుంది?

Python ఎలా పనిచేస్తుంది?

Python ఎలా పనిచేస్తుంది?

మనము Python code రాసినప్పుడు, ఆ code వెంటనే computer అర్థం చేసుకోదు. Python code ను Python interpreter చదివి, అర్థం చేసుకుని, ఒక్కో instruction ను అమలు చేస్తుంది.

Python code పనిచేసే సాధారణ విధానం

  1. మనం Python source code రాస్తాము.
  2. Python interpreter ఆ code ను చదువుతుంది.
  3. Code లోని instructions ను అర్థం చేసుకుంటుంది.
  4. Instructions ను సాధారణంగా పై నుంచి కిందికి క్రమంగా అమలు చేస్తుంది.
  5. అమలు చేసిన ఫలితాన్ని screen పై చూపిస్తుంది.

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

Python మన instructions ను computer పనులుగా మార్చడానికి ఉపయోగపడుతుంది. ఉదాహరణకు, calculations చేయడం, text చూపించడం, files తో పనిచేయడం, websites మరియు applications తయారు చేయడం వంటి పనులు Python ద్వారా చేయవచ్చు.

Python code execution flow

ఒక Python program లో మొదటి line ముందుగా అమలు అవుతుంది. ఆ తరువాత రెండవ line, తరువాత మూడవ line అమలు అవుతాయి. ఏదైనా line లో error ఉంటే, సాధారణంగా అక్కడే program ఆగిపోతుంది మరియు Python error message చూపిస్తుంది.

Python internally code ను process చేసి computer అర్థం చేసుకునే విధంగా అమలు చేస్తుంది. ఈ ప్రక్రియలో interpreter ముఖ్యమైన పాత్ర పోషిస్తుంది. Interpreter గురించి మరింత వివరంగా తరువాతి lesson లో నేర్చుకుంటాము.

Code రాసి run చేయడం

Python code ను Python file లో రాయవచ్చు లేదా Python interactive shell లో నేరుగా run చేయవచ్చు. File ను run చేసినప్పుడు interpreter ఆ file లోని instructions ను చదివి execute చేస్తుంది.

Simple Explanation

సులభంగా చెప్పాలంటే, Python ఒక translator లాగా పనిచేస్తుంది. మనం English-like Python instructions రాస్తాము. Python interpreter వాటిని చదివి computer చేయాల్సిన పనులుగా మార్చి అమలు చేస్తుంది.

ఉదాహరణకు, print() instruction కనిపిస్తే, interpreter ఆ instruction ను అమలు చేసి text ను screen పై చూపిస్తుంది.

Real-Life Example

ఒక restaurant లో customer order ఇచ్చినప్పుడు, waiter ఆ order ను kitchen staff కు చెబుతాడు. Kitchen staff order ను అర్థం చేసుకుని ఒక్కో item తయారు చేస్తారు. ఇక్కడ customer ఇచ్చిన order Python code లాంటిది, waiter interpreter లాంటివాడు, తయారైన food output లాంటిది.

అదేవిధంగా Python interpreter మన code ను చదివి, computer చేయాల్సిన పనిని అమలు చేస్తుంది.

Code Examples

Python instructions క్రమంగా అమలు అవడం

print("Python starts")
first_number = 10
second_number = 5
total = first_number + second_number
print(total)

ఈ program లో Python code పై నుంచి కిందికి ఎలా execute అవుతుందో చూడవచ్చు. ముందుగా text screen పై కనిపిస్తుంది. తరువాత రెండు numbers variables లో store అవుతాయి. తరువాత వాటి addition చేసి result ను screen పై చూపిస్తుంది.

Python starts
15

Line-by-Line Explanation

print(“Python starts”)
ఈ line Python కు text ను screen పై చూపించమని చెబుతుంది. Interpreter ఈ instruction ను execute చేసినప్పుడు Python starts అనే text output గా కనిపిస్తుంది.
first_number = 10
ఈ line లో 10 అనే value ను first_number అనే variable లో ఉంచుతాము. Interpreter ఈ value ను గుర్తుంచుకుంటుంది.
second_number = 5
ఈ line లో 5 అనే value ను second_number అనే variable లో ఉంచుతాము. తరువాత calculation లో ఈ value ఉపయోగించబడుతుంది.
total = first_number + second_number
ఈ line లో interpreter రెండు variables లోని values ను తీసుకుని addition చేస్తుంది. 10 + 5 ఫలితం 15 ను total variable లో ఉంచుతుంది.
print(total)
ఈ line లో total variable లో ఉన్న value screen పై చూపించబడుతుంది. అందువల్ల output లో 15 కనిపిస్తుంది.

Try It

Try this Python code:

Example

print("Learning Python execution")
number = 7
double_number = number * 2
print(double_number)

Try It Yourself »

Practice

Practice: పై practice code ను పూర్తి చేయండి. price1 మరియు price2 విలువలను కలిపి total అనే variable లో ఉంచి, ఆ total ను print చేయండి.

Hint: total = price1 + price2 అనే విధానాన్ని ఉపయోగించండి.

Practice: ఒక కొత్త Python program రాయండి. మొదట Program started ను print చేయండి. తరువాత number = 8 ఉంచి, దాని మూడు రెట్లను calculate చేసి print చేయండి.

Hint: ముందుగా triple = number * 3 అని రాసి, తరువాత print(triple) ఉపయోగించండి.

Common Mistakes

Code lines ను సరైన క్రమంలో రాయకుండా result variable ను ముందే ఉపయోగించడం.
ముందుగా values ను variables లో ఉంచి, తరువాత calculation చేసి, చివరలో print చేయాలి.
Text ను quotes లేకుండా రాయడం, ఉదాహరణకు print(Hello).
Text ను double quotes లేదా single quotes లో రాయాలి. ఉదాహరణకు print("Hello").
Variable name లో ఉంచిన value ను కాకుండా variable name ను తప్పుగా రాయడం.
Variable ను create చేసినప్పుడు ఉపయోగించిన spelling నే తరువాత కూడా అదే విధంగా ఉపయోగించాలి.
ఒక line లో error వచ్చినా, తరువాతి lines కూడా తప్పకుండా execute అవుతాయని అనుకోవడం.
Python సాధారణంగా error వచ్చిన line వద్ద program ను ఆపుతుంది. ముందుగా error ను సరిచేసి మళ్లీ run చేయాలి.

Interview Questions

Python program ను ఎవరు చదివి execute చేస్తారు?

Answer: Python interpreter program ను చదివి, అర్థం చేసుకుని execute చేస్తుంది.

Python code సాధారణంగా ఏ క్రమంలో execute అవుతుంది?

Answer: Python code సాధారణంగా పై నుంచి కిందికి, అంటే రాసిన క్రమంలో execute అవుతుంది.

Python interpreter యొక్క ప్రధాన పని ఏమిటి?

Answer: మనము రాసిన Python instructions ను process చేసి computer చేయాల్సిన పనులను అమలు చేయడం interpreter యొక్క ప్రధాన పని.

Python code లో error ఉంటే ఏమవుతుంది?

Answer: సాధారణంగా Python error వచ్చిన line వద్ద program ను ఆపి, error message చూపిస్తుంది.

Exam Questions

Python code ను computer అర్థం చేసుకుని execute చేయడానికి సహాయపడేది ఏమిటి?

Answer:

Python interpreter.

Python program execution యొక్క సరైన క్రమాన్ని రాయండి.

Answer:

Source code రాయడం, interpreter code ను చదవడం, instructions ను అర్థం చేసుకోవడం, వాటిని execute చేయడం, output పొందడం.

క్రింది code output ఏమిటి? print(“Start”) number = 4 print(number)

Answer:

Output రెండు lines లో వస్తుంది: Start మరియు 4.

Python program లో మొదటి line ముందుగా execute అవుతుందా?

Answer:

అవును. సాధారణంగా Python code పై నుంచి కిందికి క్రమంగా execute అవుతుంది.

Quick Revision

  • Python interpreter మన Python code ను చదివి execute చేస్తుంది.
  • Python program సాధారణంగా పై నుంచి కిందికి క్రమంగా అమలు అవుతుంది.
  • print() output ను screen పై చూపిస్తుంది.
  • Variables లో values ను ఉంచి, తరువాత calculations చేయవచ్చు.
  • Error వచ్చినప్పుడు program సాధారణంగా ఆ line వద్ద ఆగుతుంది.
  • Code రాయడం, run చేయడం, output చూడడం ద్వారా Python execution ను అర్థం చేసుకోవచ్చు.

Test Your Knowledge

Take a short quiz based on this lesson.

10 Questions • Results
Scroll to Top