dev.rean.me
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

Share:

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 int or str before.

๐ŸŽฅ 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:

TypeExampleMean
int10, -5, 0Whole number
float3.14, -0.5Number 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_name is better than x.
  • 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" not Hello.
  • 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


๐Ÿ“š Related Post

โ† Back to python
Share: