Nội dung bài họcLesson content
Python là gì?What is Python?
Python là ngôn ngữ lập trình văn bản (text-based) phổ biến nhất thế giới. Cú pháp đơn giản, dễ đọc, gần với tiếng Anh. Python dùng trong AI, web, game, khoa học dữ liệu. Bạn có thể chạy Python online tại replit.com hoặc cài trên máy.Python is the world's most popular text-based programming language. Its syntax is simple, readable, and close to English. Python is used in AI, web, games, and data science. You can run Python online at replit.com or install it locally.
Lệnh print()The print() command
Lệnh print() hiển thị chữ lên màn hình. Chữ muốn hiển thị đặt trong ngoặc đơn và dấu nháy. Ví dụ: print("Xin chào!") sẽ in ra "Xin chào!". Bạn có thể in nhiều dòng bằng nhiều lệnh print.The print() command displays text on the screen. The text to display goes inside parentheses and quotes. For example: print("Hello!") prints "Hello!". You can print multiple lines with multiple print statements.
print("Xin chào!")
print("Tôi đang học Python")
print("Hello!")
print("I am learning Python")
Biến trong PythonVariables in Python
Biến trong Python không cần khai báo trước. Gán giá trị trực tiếp: tên = "An", tuổi = 22. Dùng print() để hiển thị: print(tên). Có thể đổi giá trị: tuổi = 23. Python tự hiểu kiểu dữ liệu (chuỗi, số).Variables in Python do not need to be declared in advance. Assign directly: name = "An", age = 22. Use print() to display: print(name). You can change the value: age = 23. Python automatically understands the data type (string, number).
ten = "An"
tuoi = 22
print("Tôi tên là", ten)
print("Tôi", tuoi, "tuổi")
# Đổi giá trị
tuoi = 23
print("Năm sau tôi", tuoi, "tuổi")
Kiểu dữ liệu cơ bảnBasic data types
Python có 3 kiểu cơ bản: (1) String (chuỗi) — chữ trong nháy, ví dụ "hello". (2) Integer (số nguyên) — số không có dấu chấm, ví dụ 22. (3) Float (số thập phân) — số có dấu chấm, ví dụ 22.5. Dùng type() để kiểm tra kiểu.Python has 3 basic types: (1) String — text in quotes, e.g. "hello". (2) Integer — whole numbers, e.g. 22. (3) Float — decimal numbers, e.g. 22.5. Use type() to check the type.
ten = "An" # string (str)
tuoi = 22 # integer (int)
cannang = 65.5 # float
print(type(ten)) # <class 'str'>
print(type(tuoi)) # <class 'int'>
print(type(cannang))# <class 'float'>