Python வழி machine learning தமிழில்: Variables and Datatypes

நாம் இந்த post இல் python இல் உள்ள variables and datatypes பற்றி பார்ப் போம். 

பொருளடக்கம் 

1. Variables & Datatypes 

2. Basic program

Variables & Datatypes 

ஒரு programming language இல் ஒரு program ஐ உருவாக்குவதற்கு  உதவுவது Variables ஆகும். Variables, data வை memory இல் வைத்துக்கொள்ளும். Python இல் variables மற்ற programming language களை விட வித்தியாசமாக இருக்கும்.  எப்படி என்றால்  python இல் variable declaration செய்யும் பொழுது datatype ஐ குறிப்பிட வேண்டிய அவசியமில்லை.  உதாரணத்திற்கு c ++ இல் variable declare செய்யும்போது கீழே உள்ளது போல declare செய்வோம்.

int a = 10;

ஆனால் python இல்

a = 10

என்று declare செய்வோம். மற்றொரு வித்தியாசம் என்னவென்று பார்த்தால் நாம் python program இல் “;” use செய்ய மாட்டோம்.

நாம் மேலும் சில உதாரணங்களை கீழே பார்ப்போம்.

x = 5         # assign variable x the value 5
y = x + 10     # assign variable y the value of x plus 10
z = y         # assign variable z the value of y

மற்ற programming language களில் உள்ளது போல python variables case sensitive ஆகும். மற்றும் variables களில் எழுத்துகள், எண்கள் மற்றும் ( _ ) கலந்து இருக்கலாம். ஆனால் variable கள் எண்களில் தொடங்கக்கூடாது.


python ஒரு dynamically typed programming மொழி ஆகும்.  அதனால் இது datatype ஐ variable இல் store ஆகும் value வை வைத்து முடிவு செய்து கொள்ளும்.


நாம் கீழே python எப்படி Datatype ஐ முடிவு செய்கிறது என்று பார்ப் போம்.

x = 1
print(type(x)) # outputs: <class 'int'>

x = 1.0
print(type(x)) # outputs: <class 'float'>

முதல் வரியில்


x=1


என்று இருக்கிறது. இது ஒரு integer value ஆகும் .அதனால் python


<class ‘int’>


என்ற output ஐ வெளியிடுகிறது.


இரண்டாவது variable ஒரு decimal value ஆகும்.  அதனால் python

<class ‘float’>

என்ற output ஐ வெளியிடுகிறது.
இந்த முறை மற்ற Data type களுக்கும் பொருந்தும்.

Basic program

நண்பர்களே, நாம் இப்பொழுது ஒரு variables and datatypes இன் basic program ஐ பார்க்கலாம்

x=10
y=x+12
print(y)
print("Data type of variable x and y" + str(type(x)) + str(type(y)))

d=1.2
print(d)
print("Data type of variable d is " + str(type(d)))

s = 'Arvin Education'
print(s)
print("Data type of variable s is " + str(type(s)))

இதன் output கீழே உள்ளது போல் இருக்கும்.

22
Data type of variable x and y<class 'int'><class 'int'>
1.2
Data type of variable d is <class 'float'>
Arvin Education
Data type of variable s is <class 'str'>

நண்பர்களே, நாம் அடுத்த பதிவில் python இல் உள்ள Control Statement பற்றி பார்ப்போம்.

நன்றி.  அடுத்த பதிவில் பார்க்கலாம்.