Numbers

Python Numbers

Python లో సంఖ్యలను store చేయడానికి Numbers data type ను ఉపయోగిస్తాం. లెక్కలు చేయడం, ధరలు చూపించడం, వయస్సు, marks, distance, temperature వంటి values ను నిర్వహించడానికి numbers ఉపయోగపడతాయి.

Python లో Number రకాలు

  • int: దశాంశం లేని పూర్ణ సంఖ్యలు. ఉదాహరణ: 10, -5, 0
  • float: దశాంశం ఉన్న సంఖ్యలు. ఉదాహరణ: 10.5, 3.14
  • complex: real part మరియు imaginary part కలిగిన సంఖ్యలు. ఉదాహరణ: 2 + 3j

Arithmetic Operators

Numbers పై calculations చేయడానికి arithmetic operators ఉపయోగిస్తాం.

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • // floor division
  • % remainder
  • ** power

Numbers ఎలా పనిచేస్తాయి?

Python లో మీరు ఒక number ను variable లో store చేసినప్పుడు, Python దాని value మరియు type ను గుర్తుంచుకుంటుంది. రెండు numbers పై operator ఉపయోగిస్తే Python ఆ calculation ఫలితాన్ని ఇస్తుంది.

Number ను ఒక type నుండి మరొక type కు మార్చడానికి int(), float() వంటి functions ఉపయోగించవచ్చు. ఉదాహరణకు int("25") string value ను integer గా మారుస్తుంది.

Simple Explanation

Number అంటే లెక్కల్లో ఉపయోగించే value. int పూర్ణ సంఖ్యలకు, float దశాంశ సంఖ్యలకు ఉపయోగిస్తాం. Python లో numbers తో addition, subtraction, multiplication, division వంటి operations సులభంగా చేయవచ్చు.

ఉదాహరణకు 10 + 5 రాస్తే ఫలితం 15 వస్తుంది. 10 / 4 రాస్తే 2.5 వస్తుంది. 10 % 4 రాస్తే మిగిలిన remainder అయిన 2 వస్తుంది.

Real-Life Example

ఒక దుకాణంలో ఒక పెన్ను ధర 25 రూపాయలు, quantity 4 అనుకుందాం. మొత్తం ధర తెలుసుకోవడానికి 25 * 4 చేయాలి. ఇక్కడ 25 మరియు 4 numbers, multiplication operator మొత్తం ధరను ఇస్తుంది.

Code Examples

Number Types గుర్తించడం

age = 20
price = 99.5
complex_number = 2 + 3j

print(type(age))
print(type(price))
print(type(complex_number))

ఈ code లో integer, float మరియు complex numbers ను variables లో store చేశాం. type() function ప్రతి value యొక్క data type ను చూపిస్తుంది.


Arithmetic Operations

a = 17
b = 5

print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** 2)

ఈ code లో రెండు integer numbers పై వివిధ arithmetic operations చేశాం. సాధారణ division / దశాంశ ఫలితాన్ని ఇవ్వవచ్చు. // పూర్తి భాగాన్ని, % remainder ను ఇస్తాయి. ** power కోసం ఉపయోగిస్తాం.

22
12
85
3.4
3
2
289

Number Conversion

number_text = "25"
number = int(number_text)

print(number + 5)
print(float(number))

number_text లోని value text రూపంలో ఉంది. int() ఉపయోగించి దాన్ని integer గా మార్చాం. తరువాత ఆ number తో calculation చేసి, దాన్ని float గా కూడా మార్చి చూపించాం.

30
25.0

Line-by-Line Explanation

age = 20

ఈ line లో 20 అనే integer value ను age variable లో store చేస్తుంది. Python దీన్ని int type గా గుర్తిస్తుంది.

price = 99.5

ఈ line లో 99.5 అనే decimal value ను price variable లో store చేస్తుంది. Decimal value కావడంతో దీని type float.

complex_number = 2 + 3j

ఈ line లో 2 + 3j అనే complex number ను variable లో store చేస్తుంది. ఇక్కడ 2 real part, 3j imaginary part.

print(type(age))

type(age) ద్వారా age value యొక్క type తెలుసుకుంటాం. print() ఆ type ను output గా చూపిస్తుంది.

print(type(price))

ఈ line price variable యొక్క type ను చూపిస్తుంది. price decimal value కాబట్టి output float వస్తుంది.

print(type(complex_number))

ఈ line complex_number యొక్క type ను చూపిస్తుంది. అందువల్ల output complex వస్తుంది.

a = 17

17 అనే integer value ను a variable లో store చేస్తుంది.

b = 5

5 అనే integer value ను b variable లో store చేస్తుంది.

print(a + b)

a మరియు b ను కలిపి addition చేస్తుంది. ఫలితం 22గా output అవుతుంది.

print(a – b)

a నుండి b ను తీసివేస్తుంది. ఫలితం 12గా output అవుతుంది.

print(a * b)

a మరియు b ను గుణిస్తుంది. ఫలితం 85గా output అవుతుంది.

print(a / b)

/ operator సాధారణ division చేస్తుంది. 17 ను 5తో భాగిస్తే 3.4 వస్తుంది.

print(a // b)

// operator floor division చేస్తుంది. Division లోని పూర్తి భాగం మాత్రమే తీసుకుని 3గా చూపిస్తుంది.

print(a % b)

% operator division తర్వాత మిగిలే remainder ను ఇస్తుంది. 17 ను 5తో భాగిస్తే remainder 2.

print(a ** 2)

** operator power కోసం ఉపయోగిస్తాం. ఇది 17 యొక్క square అయిన 289ను చూపిస్తుంది.

number_text = “25”

ఇక్కడ 25 quotes లో ఉంది కాబట్టి అది text value. దాన్ని calculation చేయడానికి ముందుగా number గా మార్చాలి.

number = int(number_text)

int() function number_text లోని text ను integer గా మారుస్తుంది. మారిన value number variable లో store అవుతుంది.

print(number + 5)

ఇప్పుడు number integer కాబట్టి దానితో 5ను కలపవచ్చు. ఫలితం 30గా output అవుతుంది.

print(float(number))

float() function integer value ను decimal number గా మారుస్తుంది. అందువల్ల output 25.0గా కనిపిస్తుంది.

Try It

Try this Python code:

Example

first_number = 12
second_number = 4

print(first_number + second_number)
print(first_number * second_number)

Try It Yourself »

Practice

Practice: ఒక rectangle యొక్క length 12 మరియు width 5. Numbers మరియు arithmetic operators ఉపయోగించి area మరియు perimeter కనుగొనండి. చివరగా area, perimeter ను వేరువేరు lines లో print చేయండి.

Hint: Area = length * width. Perimeter = 2 * (length + width).

Practice: ఒక product ధర 75 మరియు quantity 3. మొత్తం ధరను calculation చేసి print చేయండి.

Hint: Total price = price * quantity.

Practice: 25 ను 4తో divide చేసినప్పుడు వచ్చే quotient మరియు remainder ను వేరువేరుగా print చేయండి.

Hint: Quotient కోసం //, remainder కోసం % ఉపయోగించండి.

Common Mistakes

10 / 2 ను integer output ఇస్తుందని అనుకోవడం.

Python లో / ఎప్పుడూ సాధారణ division చేస్తుంది మరియు సాధారణంగా float result ఇస్తుంది. పూర్తి భాగం మాత్రమే కావాలంటే // ఉపయోగించండి.

Number ను quotes లో రాసి నేరుగా calculation చేయడం. ఉదాహరణకు "25" + 5.

Quotes లో ఉన్న value text. Calculation ముందు int("25") లేదా float("25") ఉపయోగించి number గా మార్చండి.

Power కోసం ^ operator ఉపయోగించడం.

Python లో power కోసం ** ఉపయోగించాలి. ఉదాహరణ: 5 ** 2.

Remainder కోసం / ఉపయోగించడం.

Remainder తెలుసుకోవడానికి % operator ఉపయోగించాలి. ఉదాహరణ: 17 % 5 ఫలితం 2.

Variable name లో value type ను తప్పుగా అర్థం చేసుకోవడం, ఉదాహరణకు decimal value ను int అనుకోవడం.

దశాంశం ఉన్న value సాధారణంగా float. Type తెలుసుకోవడానికి type() ఉపయోగించండి.

Interview Questions

Python లో ప్రధాన number types ఏవి?

Answer: ప్రధానంగా int, float, complex number types ఉన్నాయి.

/ మరియు // operators మధ్య తేడా ఏమిటి?

Answer: / సాధారణ division చేసి decimal result ఇవ్వవచ్చు. // floor division చేసి పూర్తి భాగాన్ని ఇస్తుంది.

Python లో remainder తెలుసుకోవడానికి ఏ operator ఉపయోగిస్తారు?

Answer: Remainder కోసం % operator ఉపయోగిస్తారు.

Python లో power కోసం ఏ operator ఉపయోగిస్తారు?

Answer: Power కోసం ** operator ఉపయోగిస్తారు. ఉదాహరణకు 2 ** 3 ఫలితం 8.

String value ను integer గా ఎలా మార్చాలి?

Answer: int() function ఉపయోగించాలి. ఉదాహరణ: int("25").

Exam Questions

క్రింది code output ఏమిటి? print(10 + 5 * 2)

Answer:

Output 20. Multiplication ముందుగా జరుగుతుంది, తరువాత addition జరుగుతుంది.

క్రింది code output ఏమిటి? print(17 // 5)

Answer:

Output 3. // పూర్తి quotient ను ఇస్తుంది.

క్రింది code output ఏమిటి? print(17 % 5)

Answer:

Output 2. 17 ను 5తో భాగించినప్పుడు remainder 2.

క్రింది values యొక్క types ఏమిటి: 10, 4.5, 2 + 3j?

Answer:

వాటి types వరుసగా int, float, complex.

Number ను float గా మార్చడానికి ఏ function ఉపయోగిస్తారు?

Answer:

float() function ఉపయోగిస్తారు. ఉదాహరణ: float(10) ఫలితం 10.0.

Quick Revision

  • Python లో numbers కోసం int, float, complex types ఉన్నాయి.
  • int పూర్ణ సంఖ్యలను, float దశాంశ సంఖ్యలను store చేస్తుంది.
  • +, -, *, / వంటి operators calculations కోసం ఉపయోగిస్తాం.
  • // పూర్తి quotient ను, % remainder ను ఇస్తాయి.
  • ** power calculation కోసం ఉపయోగిస్తాం.
  • int() మరియు float() functions number conversion కోసం ఉపయోగిస్తాం.
  • type() function value యొక్క data type ను చూపిస్తుంది.

Test Your Knowledge

Take a short quiz based on this lesson.

10 Questions • Results
Scroll to Top