变量与数据类型
# 示例:变量赋值
message = "Hello, Python!" # 字符串类型
count = 42 # 整数类型
price = 3.14 # 浮点数类型
is_active = True # 布尔类型
控制结构
# 条件判断
if count > 10:
print("Count is large")
elif count == 10:
print("Count is equal")
else:
print("Count is small")
# 循环结构
for i in range(5):
print(f"循环次数: {i}")
while is_active:
print("正在运行...")
is_active = False
函数定义
def greet(name):
"""这是一个注释文档"""
return f"你好, {name}!👋"
# 调用函数
greet("社区")
扩展阅读
如需深入了解Python进阶特性,可访问 Python高级语法教程 获取更多知识 🚀