Skip to content

Python 基础语法

变量与类型

Python 是动态类型语言,不需要显式声明变量类型。

python
x = 10          # 整数
name = "Alice"  # 字符串
is_valid = True # 布尔值

列表操作

列表(List)是 Python 中最常用的数据结构之一。

python
fruits = ["apple", "banana", "cherry"]
fruits.append("date")
print(fruits)

循环

python
for fruit in fruits:
    print(f"I like {fruit}")

Released under the MIT License.