Galle, LK--:--5/6 sites live

Python Basics

NumPy, Pandas, scikit-learn — මේ හැම library එකක්ම යටින් තියෙන්නෙ සරල Python. මූලික දේවල් හරියට නැත්නම්, පස්සේ එන error messages ටිකත් clue එකක් නෙවෙයි, mystery එකක් වගේ පේනවා.

Every ML library — NumPy, Pandas, scikit-learn — is just Python underneath. If the basics are shaky, every error message later looks like magic instead of a clue.

1 May 20263 min readSelf Guide · Stage 13#Python & Data Basics#Python Fundamentals#Machine learning

Lesson 2 of 64 · Part 1 · Python & Data Basics · Python Fundamentals · bilingual notes (English + සිංහල)

Why this matters. Every ML library — NumPy, Pandas, scikit-learn — is just Python underneath. If the basics are shaky, every error message later looks like magic instead of a clue.

සිංහලෙන්: NumPy, Pandas, scikit-learn — මේ හැම library එකක්ම යටින් තියෙන්නෙ සරල Python. මූලික දේවල් හරියට නැත්නම්, පස්සේ එන error messages ටිකත් clue එකක් නෙවෙයි, mystery එකක් වගේ පේනවා.

What you'll use this for. You'll use variables and print statements in literally every notebook in this course — this is the one lesson you cannot skip.

සිංහලෙන්: මේ පාඨමාලාවේ හැම notebook එකකම variables සහ print statements පාවිච්චි වෙනවා — මේ තමයි මග හැරෙන්න බැරි එකම පාඩම.

Key principles

  • Variables are just labelled boxes. x = 10 doesn't do maths — it puts the value 10 in a box named x, so you can use it later without retyping it.
    Variables කියන්නෙ label කරපු boxes විතරයි
  • print() is how Python talks back to you. Code that runs silently could be doing anything. print() is your first, simplest debugging tool.
    print() කියන්නෙ Python ඔයාට කතා කරන විදිහ

Walkthrough

Programming Languages used for Machine Learning:

  1. Python
  2. R

#print function

ExamplePython
print("Machine Learning")

Output

Output
Machine Learning
ExamplePython
print("Machine Learning" + " Projects")

Output

Output
Machine Learning Projects
ExamplePython
print(8)

Output

Output
8
ExamplePython
print(8+3)

Output

Output
11

#Basic Data types:

  1. int
  2. float
  3. str
ExamplePython
type(8)

Output

Output
int
ExamplePython
type(5.3)

Output

Output
float
ExamplePython
type("english")

Output

Output
str

#Constants & Variables

ExamplePython
marvel_super_hero = "Iron Man"
print(marvel_super_hero)

Output

Output
Iron Man
ExamplePython
marvel_super_hero = "Captain America"
print(marvel_super_hero)

Output

Output
Captain America
ExamplePython
hero1 , hero2 , hero3 = "Iron Man" , "Captain America" , "Bat Man"
print(hero1)
print(hero2)
print(hero3)

Output

Output
Iron Man
Captain America
Bat Man
ExamplePython
x = y = z = 23
print(x)
print(y)
print(z)

Output

Output
23
23
23

input Function

ExamplePython
number_1 = int(input("Enter the first number : "))
number_2 = int(input("Enter the second number : "))

sum = number_1 + number_2
print(sum)

Output

Output
Enter the first number : 23
Enter the second number : 23
46
ExamplePython
# changing the data type in python:
num = 5
print(float(num))

Output

Output
5.0

Keep going: ← Lesson 1 · Lesson 3 → · Track it in the Self Guide