python
04 How to Create Variable and Data Types in Python (Video in Khmer)
Learn Python variable, number and string with simple example and tips. Short and clear. Good for beginner!
2026-10-18 ยท 5 min read
Hello friend! ๐ Every program need to keep data. In Python, we use variable for this.
In this post, I show you variable and data types in Python. Easy and short. ๐
๐ฆ What is Variable?
Variable is like a box with a name. You put data inside the box. Later you can use the data again.
name = "Dara"
age = 20
print(name)
print(age)
Output:
Dara
20
=mean put value into variable. It is not "equal" like in math.- Python find the type by itself. No need write
intorstrbefore.
๐ฅ Video: Use Variable in Python (Khmer)
โ Variable Name Rule
- Can use letter, number and
_ - Cannot start with number
- Cannot have space
- Cannot use Python keyword like
if,for,class - Big letter and small letter are different:
Ageโage
user_name = "Sok" # good
user2 = "Sophea" # good
2user = "Bad" # error
user name = "Bad" # error
๐ข Number Data Type
Python have 2 main number type:
| Type | Example | Mean |
|---|---|---|
int | 10, -5, 0 | Whole number |
float | 3.14, -0.5 | Number with dot |
apple = 5
price = 1.25
total = apple * price
print(total)
Output:
6.25
โ Math Operator
a = 10
b = 3
print(a + b) # 13 add
print(a - b) # 7 minus
print(a * b) # 30 multiply
print(a / b) # 3.3333333333333335 divide
print(a // b) # 3 divide, keep whole number only
print(a % b) # 1 remainder
print(a ** b) # 1000 power
๐ฅ Video: Using Numbers Data Type in Python (Khmer)
๐ค String Data Type
String is text. Put it inside " " or ' '.
first = "Hello"
second = 'Python'
print(first + " " + second)
Output:
Hello Python
โ Useful String Example
text = "python"
print(text.upper()) # PYTHON
print(text.capitalize())# Python
print(len(text)) # 6
print(text[0]) # p (first letter)
print(text[-1]) # n (last letter)
print(text[0:3]) # pyt (slice)
๐ฅ Video: Using String Data Type in Python (Khmer)
โ String Part 2: f-string and More
Use f-string to put variable inside text. Very easy!
name = "Dara"
age = 20
print(f"My name is {name}, I am {age} years old.")
Output:
My name is Dara, I am 20 years old.
More string trick:
text = " Hello Python "
print(text.strip()) # "Hello Python" remove space
print(text.replace("Python", "World"))
print("Hello Python".split()) # ['Hello', 'Python']
print("py" in "python") # True
๐ฅ Video: Using String Data Type in Python Part 2 (Khmer)
๐ Check Type with type()
print(type(10)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type("Hello")) # <class 'str'>
โ Common Error
Cannot add number and string directly:
age = 20
print("I am " + age)
Error:
TypeError: can only concatenate str (not "int") to str
Fix: use str() or f-string.
print("I am " + str(age))
print(f"I am {age}")
Input always give string:
num = input("Enter number: ")
print(num + 1) # error
print(int(num) + 1) # good
๐ก Tips
- Use clear name:
student_nameis better thanx. - Use snake_case for variable name in Python:
total_price. - Use f-string for print text with variable. Easy to read.
- Don't forget quote for string:
"Hello"notHello. - Use
type()when you not sure what type it is. - Use
int(),float(),str()to change type. - Use
#to write comment and note your code.
โ Any Question?
Tell us in comment below! ๐
#Python #Variable #DataTypes #String #Number #LearnPython