Python Numbers

பைத்தான் எண்கள்

Python Numbers

பைத்தானில் மூன்று எண் வகைகள் உள்ளன:

🔢
int
முழு எண்கள் (Integers)
📐
float
மிதவை புள்ளி எண்கள் (Floating point)
🌀
complex
சிக்கலான எண்கள் (Complex numbers)

நீங்கள் ஒரு மதிப்பை ஒதுக்கும் போது எண் வகை மாறிகள் உருவாக்கப்படுகின்றன:

Example

x = 1    # int
y = 2.8  # float
z = 1j   # complex

பைத்தானில் எந்த பொருளின் வகையையும் சரிபார்க்க, type() செயல்பாட்டைப் பயன்படுத்தவும்:

Example

print(type(x))
print(type(y))
print(type(z))

Int

Int, அல்லது integer, என்பது ஒரு முழு எண், நேர்மறை அல்லது எதிர்மறை, தசமங்கள் இல்லாமல், வரம்பற்ற நீளம் கொண்டது.

Example

x = 1
y = 35656222554887711
z = -3255522

print(type(x))
print(type(y))
print(type(z))

Float

Float, அல்லது "floating point number" என்பது ஒன்று அல்லது அதற்கு மேற்பட்ட தசமங்களைக் கொண்ட ஒரு எண்ணாகும், நேர்மறை அல்லது எதிர்மறை.

Example

x = 1.10
y = 1.0
z = -35.59

print(type(x))
print(type(y))
print(type(z))

Float என்பது "e" உடன் அறிவியல் எண்களாகவும் இருக்கலாம், இது 10 இன் சக்தியைக் குறிக்கிறது.

Example

x = 35e3
y = 12E4
z = -87.7e100

print(type(x))
print(type(y))
print(type(z))

Complex

சிக்கலான எண்கள் கற்பனை பகுதியாக "j" உடன் எழுதப்படுகின்றன:

Example

x = 3+5j
y = 5j
z = -5j

print(type(x))
print(type(y))
print(type(z))

Type Conversion

நீங்கள் int(), float(), மற்றும் complex() முறைகளுடன் ஒரு வகையிலிருந்து மற்றொரு வகைக்கு மாற்றலாம்:

Example

x = 1    # int
y = 2.8  # float
z = 1j   # complex

#convert from int to float:
a = float(x)

#convert from float to int:
b = int(y)

#convert from int to complex:
c = complex(x)

print(a)
print(b)
print(c)

print(type(a))
print(type(b))
print(type(c))

குறிப்பு: சிக்கலான எண்களை மற்றொரு எண் வகையாக மாற்ற முடியாது.

Random Number

பைத்தானில் சீரற்ற எண்ணை உருவாக்க random() செயல்பாடு இல்லை, ஆனால் பைத்தானில் random என்ற உள்ளமைக்கப்பட்ட தொகுதி உள்ளது, இது சீரற்ற எண்களை உருவாக்க பயன்படுத்தப்படலாம்:

Example

import random

print(random.randrange(1, 10))

எங்கள் Random Module Reference இல் நீங்கள் Random தொகுதி பற்றி மேலும் அறிவீர்கள்.

Exercise

பைத்தானில் சட்டபூர்வமான எண் தரவு வகை அல்லாதது எது?

int
✗ தவறு! int என்பது பைத்தானில் சட்டபூர்வமான எண் தரவு வகையாகும்
long
✓ சரி! long என்பது பைத்தான் 2 இல் இருந்தது, ஆனால் பைத்தான் 3 இல் int ஆக இணைக்கப்பட்டது
float
✗ தவறு! float என்பது பைத்தானில் சட்டபூர்வமான எண் தரவு வகையாகும்