Lectures: Nguyễn Tuấn Phong, Đào Việt Anh
Labs: Trịnh Ngọc Huỳnh, Phạm Tiến Du
Semester: 2025-2026-1
Institute for AI, VNU-UET
Can you name some examples of data generated in your daily life, or data you have encountered?
Data-driven decision making process
✅ Processing turns raw data into usable information.
Raw data (messy logs)
User123, 2025-09-01 09:14:32, SongID_981, action=skip
User123, 2025-09-01 09:15:05, SongID_472, action=play
User456, 2025-09-01 09:16:20, SongID_981, action=play
User789, 2025-09-01 09:17:45, SongID_981, action=play
Processing steps
Raw data (messy logs)
User123, 2025-09-01 09:14:32, SongID_981, action=skip
User123, 2025-09-01 09:15:05, SongID_472, action=play
User456, 2025-09-01 09:16:20, SongID_981, action=play
User789, 2025-09-01 09:17:45, SongID_981, action=play
Usable data (features)
print("Hello, world!")
x = 5
y = 2 * x
print("y = ", y)
Let's run this code in a Python environment:
x = 5 # definition
print(x) # command
When should we use:
💡 Use type() to see the type of an object
>>> type(5)
int
>>> type(3.0)
float
Converts object of one type to another
>>> float(3)
3.0
>>> int(3.9)
3
In [11]: 3+2
Out[11]: 5
In [12]: print(3+2)
5
>>> type(3 + 5)
int
| Expression | Meaning | Result type |
|---|---|---|
| i + j | sum | int if both ints, else float |
| i - j | difference | |
| i * j | product | |
| i / j | division | always float |
| i // j | floor division | ? |
| i % j | remainder | ? |
| i ** j | power | ? |
>>> 2 + 3 * 4
14
>>> (2 + 3) * 4
20
The equal sign (=) is an assignment of a value to a variable name.
pi = 3.14159 # pi is a name, 3.14159 is a value
pi_approx = 22/7 # pi_approx is a name, 22/7 is a value
Why give names to values of expressions?
pi = 3.14159
radius = 2.2
length = 2 * pi * radius
area = pi * (radius ** 2)
pi = 3.14159
radius = 2.2
area = pi * (radius ** 2) # area of circle
radius = radius + 1
pi = 3.14
radius = 2.2
area = pi * (radius ** 2)
radius = radius + 1
>>> hi = "hello there"
>>> name = 'ana'
>>> hi + name
hello thereana
>>> hi + " " + name
hello there ana
>>> hi + " " + name * 3
hello there anaanaana
Use print() to output stuff to console
>>> x = 1
>>> print(x)
1
>>> x_str = str(x)
>>> print("my fav num is", x, ".", "x =", x)
my fav num is 1 . x = 1
>>> print("my fav num is " + x_str + ". " + "x = " + x_str)
my fav num is 1. x = 1
>>> text = input("Type anything... ")
Type anything... hello
>>> print(5 * text)
hellohellohellohellohello
>>> text = input("Type anything... ")
Type anything... 7
>>> print(5 * text)
77777
>>> num = int(input("Type a number... "))
Type a number... 7
>>> print(5 * num)
35
| a | b | a and b | a or b |
|---|---|---|---|
| True | True | True | True |
| True | False | False | True |
| False | True | False | True |
| False | False | False | False |
Truth table for logic operators
>>> pset_time = 15
>>> sleep_time = 8
>>> print(sleep_time > pset_time)
False
>>> drive = True
>>> drink = False
>>> both = drink and drive
>>> print(both)
False