base_rag/documents/python_guide_a94a6076.md

71 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Python编程指南
## 基础语法
Python是一种高级编程语言以其简洁明了的语法而闻名。
### 变量和数据类型
```python
# 字符串
name = "Python"
# 整数
age = 30
# 浮点数
pi = 3.14159
# 布尔值
is_programming = True
```
### 控制结构
#### 条件语句
```python
if age >= 18:
print("成年人")
else:
print("未成年人")
```
#### 循环
```python
for i in range(5):
print(f"数字: {i}")
while count > 0:
print(count)
count -= 1
```
## 函数定义
```python
def greet(name):
return f"Hello, {name}!"
def calculate_area(radius):
return 3.14159 * radius ** 2
```
## 面向对象编程
```python
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
return f"我是{self.name},今年{self.age}岁"
```
## 常用库
- **NumPy**: 科学计算
- **Pandas**: 数据分析
- **Matplotlib**: 数据可视化
- **Requests**: HTTP请求
- **Flask/Django**: Web开发
Python是学习编程的绝佳选择适合初学者入门。