Python 是什么?

Python 是一门简洁优雅的编程语言,适合初学者入门。

第一个程序

1
print("Hello, World!")

变量与数据类型

1
2
3
4
name = "小明"        # 字符串
age = 20             # 整数
height = 175.5       # 浮点数
is_student = True    # 布尔值

条件判断

1
2
3
4
5
6
7
8
score = 85

if score >= 90:
    print("优秀")
elif score >= 60:
    print("及格")
else:
    print("继续加油")

循环

1
2
3
4
5
6
7
8
9
# for 循环
for i in range(5):
    print(f"第 {i+1} 次循环")

# while 循环
count = 0
while count < 3:
    print(f"count = {count}")
    count += 1

学习资源


下一篇预告: Python 函数与模块