Python 基础知识
让我们开始学习 Python 的基础知识。
第一个 Python 程序
print("Hello, World!")
变量和数据类型
Python 中的基本数据类型包括:
- 整数 (int)
- 浮点数 (float)
- 字符串 (str)
- 布尔值 (bool)
# 整数
age = 25
# 浮点数
height = 1.75
# 字符串
name = "Python"
# 布尔值
is_student = True
列表和字典
列表
fruits = ["apple", "banana", "orange"]
print(fruits[0]) # 输出: apple
字典
person = {
"name": "John",
"age": 30,
"city": "New York"
}
print(person["name"]) # 输出: John
条件语句
age = 18
if age >= 18:
print("成年人")
else:
print("未成年人")