Basic Data Types in Python
Model එකකට තේරෙන්නෙ නැති shape එකක් තියෙන data එකකින් ඉගෙන ගන්න බෑ. int, float, string, bool අතර වෙනස දැනගැනීම තමයි, ගණනය කිරීමක් නිශ්ශබ්දව වැරදි වෙන්නෙ ඇයි කියලා තේරෙන්නෙ.
A model can't learn from data it doesn't understand the shape of. Knowing int vs float vs string vs bool is what lets you spot why a calculation is silently wrong.
Lesson 3 of 64 · Part 1 · Python & Data Basics · Python Fundamentals · bilingual notes (English + සිංහල)
Why this matters. A model can't learn from data it doesn't understand the shape of. Knowing int vs float vs string vs bool is what lets you spot why a calculation is silently wrong.
සිංහලෙන්: Model එකකට තේරෙන්නෙ නැති shape එකක් තියෙන data එකකින් ඉගෙන ගන්න බෑ. int, float, string, bool අතර වෙනස දැනගැනීම තමයි, ගණනය කිරීමක් නිශ්ශබ්දව වැරදි වෙන්නෙ ඇයි කියලා තේරෙන්නෙ.
What you'll use this for. Almost every bug in a Pandas pipeline traces back to a column being the wrong data type — this lesson is what lets you actually fix that.
සිංහලෙන්: Pandas pipeline එකක වෙන bugs ගොඩක් හේතුව column එකක data type එක වැරදි එක — මේ පාඩම තමයි ඒක fix කරන්න උදව් කරන්නෙ.
Key principles
- Types decide what an operator means.
"3" + "3"gives"33", but3 + 3gives6. Same symbol, completely different result — because the types differ.
Type එක තමයි operator එකේ තේරුම තීරණය කරන්නෙ
Walkthrough
Basic Data Types in Python:
- Integer
- Floating Point
- Complex
- Boolean
- String
# integers
a = 8
print(a)Output
8type(a)Output
int# floating point
b = 2.3
print(b)
type(b)Output
2.3Output
float# complex numbers
c = 1 + 3j
print(c)
type(c)Output
(1+3j)Output
complexConversion of one data type to another
# int to float
x = 10
print(x)
type(x)Output
10Output
inty = float(x)
print(y)
type(y)Output
10.0Output
float# float to int
x = 5.88
print(x)
type(x)Output
5.88Output
floaty = int(x)
print(y)
type(y)Output
5Output
intBoolean
- True
- False
a = True
print(a)
type(a)Output
TrueOutput
boolb = False
print(b)
type(b)Output
FalseOutput
boola = 7 < 3
print(a)
type(a)Output
FalseOutput
boola = 7 > 3
print(a)
type(a)Output
TrueOutput
boolString
print("Machine Learning")Output
Machine Learningprint('Machine Learning')Output
Machine Learningmy_string = "Machine Learning"
print(my_string)
type(my_string)Output
Machine LearningOutput
strprint("Hello"*5)Output
HelloHelloHelloHelloHelloSlicing
my_string = "Programming"print(my_string[1:5]) # values from index 1 to 5-1 will be slicedOutput
rogr# step
print(my_string[0:10:2])Output
PormiString Concatenation
word_1 = 'Machine '
word_2 = 'Learning'
print(word_1+word_2)Output
Machine LearningKeep going: ← Lesson 2 · Lesson 4 → · Track it in the Self Guide
Finished this one?
Part of Self Guide · Stage 13: ML 1 — Python & Data Basics. Progress is saved in this browser.



