跳到主要内容
C++ 开发者转 Python:完整学习与实战指南 | 极客日志
Python AI 算法
C++ 开发者转 Python:完整学习与实战指南 综述由AI生成 对具备 3-5 年 C++ 开发经验的工程师,系统梳理了从 C++ 转向 Python 的学习路径。内容涵盖语言设计哲学差异、编译与解释执行模式、静态与动态类型对比、内存管理机制变迁以及核心语法与数据结构的映射关系。通过大量并列代码示例,展示了 C++ STL 与 Python 内置类型的对应关系,重点讲解了 Pythonic 编程习惯、常见陷阱规避及实战项目建议。文章旨在帮助 C++ 开发者快速建立 Python 思维,理解两者互补优势,从而在 Web 开发、数据科学及自动化等领域拓展技术栈。
C++ 开发者转 Python:完整学习与实战指南
适合人群 :具有 3-5 年 C++ 开发经验的中级开发者
作为一名 C++ 开发者,你已经掌握了编程的核心概念:变量、循环、条件判断、函数、类、内存管理等。这些宝贵的经验将使你学习 Python 时如虎添翼。Python 不是要取代 C++,而是为你的技术栈增添一把利器。
1. 引言:为什么 C++ 开发者要学 Python
相比编程新手,你可以在 1-2 周内掌握 Python 基础,4-6 周达到生产力水平。选择与你当前工作相关的领域作为切入点,这样能快速产生价值并保持学习动力。
1.1 Python 的应用场景
应用领域 典型场景 主要框架/库 C++ 背景优势 Web 开发 后端服务、API 开发 Django, Flask, FastAPI 理解 HTTP 协议和服务架构 数据科学 数据分析、可视化 Pandas, NumPy, Matplotlib 理解算法和数学基础 人工智能 机器学习、深度学习 TensorFlow, PyTorch, scikit-learn 数学基础和算法优化思维 自动化脚本 系统管理、批处理 os, subprocess, pathlib 理解操作系统和文件系统 DevOps CI/CD、基础设施自动化 Ansible, Fabric 系统级编程经验 科学计算 数值计算、仿真 SciPy, SymPy 数学和算法背景 游戏开发 游戏脚本、工具开发 Pygame, Panda3D 图形和引擎架构理解 网络爬虫 数据采集 Scrapy, BeautifulSoup 网络协议知识
1.2 学习收益
mindmap root((学习 Python 的收益))
开发效率
快速原型开发
代码量减少 50-80%
丰富的第三方库
减少编译等待时间
职业发展
更广的就业机会
数据科学转型可能
全栈开发能力
开源社区参与
技术互补
Python 做快速开发
C++ 做性能关键部分
两者可以互操作
发挥各自优势
思维提升
动态类型思维
函数式编程
更简洁的代码风格
新的问题解决方式
1.2.1 开发速度提升
同样的功能,Python 代码量通常只有 C++ 的 20-50%:
#include <iostream>
#include <fstream>
#include <map>
{
;
std::map<std::string, > word_count;
std::string word;
(file >> word) {
word_count[word]++;
}
( & pair : word_count) {
std::cout << pair.first << << pair.second << std::endl;
}
;
}
#include <string>
#include <sstream>
int main ()
std::ifstream file ("data.txt" )
int
while
for
const
auto
": "
return
0
from collections import Counter
with open ('data.txt' ) as file:
words = file.read().split()
word_count = Counter(words)
for word, count in word_count.items():
print (f"{word} : {count} " )
代码行数 : C++ 18 行 vs Python 6 行(减少 67%)
1.2.2 技术栈互补 C++ 和 Python 并非竞争关系,而是互补:
场景 推荐语言 原因 性能关键代码 C++ 底层优化、高性能计算 快速原型开发 Python 开发速度快、试错成本低 系统底层 C++ 直接内存控制、硬件交互 数据分析 Python 丰富的数据处理库 游戏引擎核心 C++ 性能要求高 游戏脚本逻辑 Python 灵活、易修改 工具和脚本 Python 快速开发、跨平台
最佳实践 : 很多项目采用"C++ 核心 + Python 胶水"的架构,用 Python 调用 C++ 编写的高性能模块。
1.2.3 新的编程视野
简洁之美 : "能用一行代码解决就不用两行"
动态类型 : 快速迭代,少写样板代码
函数式编程 : map, filter, lambda 等函数式特性
鸭子类型 : "如果它走起来像鸭子,叫起来像鸭子,那它就是鸭子"
丰富生态 : 30 万 + 开源包,几乎所有问题都有现成方案
2. 思维转换:两种语言的设计哲学 在深入学习 Python 语法之前,理解两种语言的设计哲学至关重要。这将帮助你避免用"C++ 思维写 Python 代码"的误区。
2.1 语言设计哲学对比 设计理念 C++ Python 核心哲学 "零开销抽象" "你不用的不需要付出代价" "简单胜于复杂" "可读性很重要" 设计目标 性能、效率、底层控制 可读性、开发效率、简洁性 目标用户 系统程序员、性能专家 快速开发者、数据科学家、初学者 语言复杂度 高(模板、多继承、内存管理等) 低(语法简洁、一种最佳方式) 学习曲线 陡峭 平缓 代码风格 可以有多种写法 强调"Pythonic"的唯一最佳写法
C++ 的哲学:"给专家提供工具"
template <typename T>
class MyVector {
private :
T* data;
size_t capacity;
size_t size;
public :
MyVector () : data (new T[10 ]), capacity (10 ), size (0 ) {}
~MyVector () { delete [] data; }
T& operator [](size_t index) { return data[index]; }
T* begin () { return data; }
T* end () { return data + size; }
};
Python 的哲学:"简洁优雅" - The Zen of Python 在 Python 中输入 import this 会显示 Python 之禅:
my_list = [1 , 2 , 3 , 4 , 5 ]
2.2 编译型 vs 解释型 graph LR
subgraph "C++ 编译型语言"
A1[源代码<br/>main.cpp] --> B1[编译器<br/>g++/clang]
B1 --> C1[机器码<br/>a.out/exe]
C1 --> D1[运行]
end
subgraph "Python 解释型语言"
A2[源代码<br/>main.py] --> B2[解释器<br/>python]
B2 --> C2[字节码<br/>.pyc]
C2 --> D2[虚拟机<br/>PVM]
D2 --> E2[运行]
end
style C1 fill:#ffe1e1
style D2 fill:#e1ffe1
特性 C++(编译型) Python(解释型) 执行前 必须编译 直接运行 开发流程 编写→编译→链接→运行 编写→运行 错误发现 编译时发现语法和类型错误 运行时才发现错误 启动速度 快(已编译为机器码) 较慢(需要解释) 运行性能 高(直接执行机器码) 较低(解释执行) 跨平台 需要为不同平台重新编译 代码无需修改即可跨平台 迭代速度 慢(每次修改需重新编译) 快(即改即运行) 调试体验 编译错误详细,运行时调试复杂 错误信息清晰,调试简单
$ vim hello.cpp
$ g++ hello.cpp
$ ./a.out
$ vim hello.py
$ python hello.py
2.3 静态类型 vs 动态类型
静态类型(C++)
int number = 42 ;
std::string text = "hello" ;
std::vector<int > numbers;
number = "hello" ;
动态类型(Python)
number = 42
number = "hello"
number = [1 , 2 , 3 ]
number = lambda x: x * 2
类型提示(Type Hints)- 两者的结合 Python 3.5+ 引入了类型提示,让你可以获得静态类型的部分好处:
def greet (name: str ) -> str :
return f"Hello, {name} "
age: int = 25
scores: list [int ] = [95 , 87 , 92 ]
age = "twenty-five"
2.4 内存管理模式
C++: 手动内存管理 + RAII
void processData () {
int x = 42 ;
int * ptr = new int (100 );
std::unique_ptr<int > smart_ptr (new int (200 )) ;
delete ptr;
}
std::ifstream file ("data.txt" ) ;
file.close ();
Python: 自动垃圾回收
def process_data ():
x = 42
data = [1 , 2 , 3 , 4 , 5 ]
text = "Hello" * 1000
with open ('data.txt' ) as file:
content = file.read()
内存管理 C++ Python 堆内存分配 new / delete自动(用户不可见) 回收机制 手动 / RAII / 智能指针 引用计数 + 垃圾回收 资源管理 RAII 模式 上下文管理器(with) 内存泄漏风险 高(如忘记 delete) 低(几乎不会) 性能开销 无 GC 开销 GC 有一定开销 开发心智负担 高 低
从 "我需要管理内存" 到 "我只需要使用对象"
从 "何时释放资源" 到 "使用 with 语句"
从 "担心内存泄漏" 到 "专注业务逻辑"
2.5 "Pythonic"思维 "Pythonic"指的是符合 Python 风格的代码编写方式。
❌ 非 Pythonic(C++ 思维写 Python)
numbers = [1 , 2 , 3 , 4 , 5 ]
for i in range (len (numbers)):
print (numbers[i])
if len (my_list) > 0 :
first = my_list[0 ]
found = False
for item in items:
if item == target:
found = True
break
if found:
print ("Found" )
✅ Pythonic 方式
numbers = [1 , 2 , 3 , 4 , 5 ]
for number in numbers:
print (number)
if my_list:
first = my_list[0 ]
if target in items:
print ("Found" )
squares = [x**2 for x in range (10 )]
squares = []
for x in range (10 ):
squares.append(x**2 )
Pythonic 的核心原则
简洁明了 : 能用一行,不用三行
直接表达 : 代码即意图
利用内置特性 : 不要重新发明轮子
可读性优先 : 代码是写给人看的
temp = a
a = b
b = temp
a, b = b, a
2.6 思维转换总结 graph TD
A[C++ 思维] -->|转换| B[Python 思维]
A1[我要控制每个细节] -->|转换| B1[我要表达业务逻辑]
A2[性能优先] -->|转换| B2[可读性优先]
A3[类型安全] -->|转换| B3[灵活动态]
A4[编译时检查] -->|转换| B4[快速迭代]
A5[手动管理资源] -->|转换| B5[自动管理资源]
A6[多种实现方式] -->|转换| B6[唯一最佳方式]
style A fill:#ffe1e1
style B fill:#e1ffe1
从(C++) 到(Python) 关注"怎么做" 关注"做什么" 追求极致性能 追求开发效率 严格的类型约束 灵活的鸭子类型 编译时安全 运行时动态 显式内存管理 专注业务逻辑 一切尽在掌控 信任语言和库
3. 核心语法对比:快速入门 掌握 Python 的基础语法是第一步。本章将通过大量对比示例,帮助你快速建立 C++ 到 Python 的语法映射。
3.1 Hello World 对比 #include <iostream>
int main () {
std::cout << "Hello, World!" << std::endl;
return 0 ;
}
❌ Python 无需 包含头文件
❌ Python 无需 main 函数
❌ Python 无需 分号结尾
❌ Python 无需 返回值
✅ Python 代码更简洁(从 5 行到 1 行)
3.2 变量和数据类型
变量声明
int age = 25 ;
double price = 99.99 ;
char grade = 'A' ;
bool is_valid = true ;
std::string name = "Alice" ;
auto count = 10 ;
auto pi = 3.14 ;
age = 25
price = 99.99
grade = 'A'
is_valid = True
name = "Alice"
age: int = 25
price: float = 99.99
基本数据类型对照表 C++ 类型 Python 类型 说明 intintPython 的 int 可以任意大小! long, long longintPython int 无大小限制 float, doublefloatPython 只有 float(双精度) charstrPython 没有单字符类型 boolboolPython 是 True/False(大写) std::stringstrPython 字符串是内置类型 voidNonePython 用 None 表示空
long long big = 9223372036854775807LL ;
big = 9223372036854775807
bigger = big ** 100
print (bigger)
类型转换 int x = 10 ;
double y = static_cast <double >(x);
std::string s = std::to_string (x);
int z = std::stoi ("42" );
x = 10
y = float (x)
s = str (x)
z = int ("42" )
b = bool (x)
3.3 控制流
if-else 语句 int score = 85 ;
if (score >= 90 ) {
std::cout << "A" << std::endl;
} else if (score >= 80 ) {
std::cout << "B" << std::endl;
} else if (score >= 70 ) {
std::cout << "C" << std::endl;
} else {
std::cout << "D" << std::endl;
}
score = 85
if score >= 90 :
print ("A" )
elif score >= 80 :
print ("B" )
elif score >= 70 :
print ("C" )
else :
print ("D" )
✅ Python 用冒号 代替大括号
✅ Python 用缩进 表示代码块(通常 4 个空格)
✅ Python 用 elif 而不是 else if
✅ Python 条件表达式不需要括号 (但可以加)
int max = (a > b) ? a : b;
max_val = a if a > b else b
for 循环
for (int i = 0 ; i < 5 ; i++) {
std::cout << i << std::endl;
}
std::vector<int > numbers = {1 , 2 , 3 , 4 , 5 };
for (int num : numbers) {
std::cout << num << std::endl;
}
for (auto it = numbers.begin (); it != numbers.end (); ++it) {
std::cout << *it << std::endl;
}
for i in range (5 ):
print (i)
numbers = [1 , 2 , 3 , 4 , 5 ]
for num in numbers:
print (num)
for index, num in enumerate (numbers):
print (f"{index} : {num} " )
for i in range (0 , 10 , 2 ):
print (i)
for (int i = start; i < end; i += step) {
}
range (stop)
range (start, stop)
range (start, stop, step)
while 循环 int i = 0 ;
while (i < 5 ) {
std::cout << i << std::endl;
i++;
}
int j = 0 ;
do {
std::cout << j << std::endl;
j++;
} while (j < 5 );
i = 0
while i < 5 :
print (i)
i += 1
while True :
print (i)
i += 1
if i >= 5 :
break
switch vs match (Python 3.10+) int day = 3 ;
switch (day) {
case 1 : std::cout << "Monday" << std::endl; break ;
case 2 : std::cout << "Tuesday" << std::endl; break ;
case 3 : std::cout << "Wednesday" << std::endl; break ;
default : std::cout << "Other day" << std::endl;
}
Python 3.9 及以下:使用 if-elif
day = 3
if day == 1 :
print ("Monday" )
elif day == 2 :
print ("Tuesday" )
elif day == 3 :
print ("Wednesday" )
else :
print ("Other day" )
day_names = {
1 : "Monday" ,
2 : "Tuesday" ,
3 : "Wednesday"
}
print (day_names.get(day, "Other day" ))
Python 3.10+: match 语句(结构模式匹配)
day = 3
match day:
case 1 :
print ("Monday" )
case 2 :
print ("Tuesday" )
case 3 :
print ("Wednesday" )
case _:
print ("Other day" )
3.4 函数定义
基本函数
int add (int a, int b) ;
int add (int a, int b) {
return a + b;
}
int result = add (3 , 5 );
def add (a, b ):
return a + b
result = add(3 , 5 )
def add (a: int , b: int ) -> int :
return a + b
默认参数
void greet (std::string name, std::string greeting = "Hello" ) {
std::cout << greeting << ", " << name << std::endl;
}
greet ("Alice" );
greet ("Bob" , "Hi" );
def greet (name, greeting="Hello" ):
print (f"{greeting} , {name} " )
greet("Alice" )
greet("Bob" , "Hi" )
greet("Bob" , greeting="Hi" )
可变参数
#include <cstdarg>
int sum (int count, ...) {
va_list args;
va_start (args, count);
int total = 0 ;
for (int i = 0 ; i < count; i++) {
total += va_arg (args, int );
}
va_end (args);
return total;
}
template <typename ... Args>
int sum (Args... args) {
return (args + ...);
}
def sum_all (*numbers ):
return sum (numbers)
print (sum_all(1 , 2 , 3 , 4 , 5 ))
def print_info (**info ):
for key, value in info.items():
print (f"{key} : {value} " )
print_info(name="Alice" , age=25 , city="NYC" )
Lambda 表达式
auto add = [](int a, int b) { return a + b; };
int result = add (3 , 5 );
int x = 10 ;
auto add_x = [x](int a) { return a + x; };
std::vector<int > nums = {3 , 1 , 4 , 1 , 5 };
std::sort (nums.begin (), nums.end (), [](int a, int b) { return a > b; });
add = lambda a, b: a + b
result = add(3 , 5 )
x = 10
add_x = lambda a: a + x
nums = [3 , 1 , 4 , 1 , 5 ]
sorted_nums = sorted (nums, key=lambda x: -x)
calc = lambda x: x**2 if x > 0 else -x**2
def calc (x ):
if x > 0 :
return x ** 2
else :
return -x ** 2
3.5 命名空间和作用域
命名空间
namespace math {
int add (int a, int b) { return a + b; }
}
namespace utils {
int add (int a, int b) { return a + b + 1 ;
}
int result1 = math::add (3 , 5 );
int result2 = utils::add (3 , 5 );
using namespace math;
int result3 = add (3 , 5 );
def add (a, b ):
return a + b
def add (a, b ):
return a + b + 1
import math_utils
import utils
result1 = math_utils.add(3 , 5 )
result2 = utils.add(3 , 5 )
from math_utils import add
result3 = add(3 , 5 )
import math_utils as mu
result4 = mu.add(3 , 5 )
作用域规则 int x = 10 ;
void func () {
int x = 20 ;
if (true ) {
int x = 30 ;
std::cout << x << std::endl;
}
std::cout << x << std::endl;
}
x = 10
def outer ():
x = 20
def inner ():
x = 30
print (x)
inner()
print (x)
outer()
print (x)
int x = 10 ;
void modify () {
x = 20 ;
}
x = 10
def modify ():
global x
x = 20
def outer ():
x = 10
def inner ():
nonlocal x
x = 20
inner()
print (x)
3.6 注释和文档
std::string greet (std::string name) {
return "Hello, " + name;
}
"""
多行注释(实际上是字符串)
第二行
"""
def greet (name ):
"""函数文档字符串(Docstring)
Args:
name (str): 要问候的人名
Returns:
str: 问候语
Examples:
>>> greet("Alice")
'Hello, Alice'
"""
return f"Hello, {name} "
print (greet.__doc__)
help (greet)
3.7 语法对照速查表 特性 C++ Python 语句结束 ; 必需换行(; 可选) 代码块 { }缩进(4 空格) 条件语句 if () { }if :否则如果 else ifelif布尔值 true, falseTrue, False空值 nullptr, NULLNone逻辑与 &&and逻辑或 ` 逻辑非 !not自增 i++, ++ii += 1幂运算 pow(x, y)x ** y整除 /(整数间)//取模 %%打印 std::cout <<print()输入 std::cin >>input()
3.8 常用操作对比
打印输出
#include <iostream>
std::cout << "Hello " << name << "!" << std::endl;
std::cout << std::format("Hello {}!" , name) << std::endl;
print ("Hello" , name, "!" )
print (f"Hello {name} !" )
print ("Hello {}!" .format (name))
用户输入
#include <iostream>
#include <string>
int age;
std::string name;
std::cout << "Enter age: " ;
std::cin >> age;
std::cout << "Enter name: " ;
std::cin.ignore ();
std::getline (std::cin, name);
age = int (input ("Enter age: " ))
name = input ("Enter name: " )
字符串操作
#include <string>
#include <algorithm>
std::string s = "hello" ;
s += " world" ;
int len = s.length ();
std::string upper = s;
std::transform (upper.begin (), upper.end (), upper.begin (), ::toupper);
s = "hello"
s += " world"
s = s + " world"
length = len (s)
upper = s.upper()
lower = s.lower()
s.startswith("he" )
s.endswith("ld" )
s.split()
" " .join(["a" , "b" ])
先掌握基础语法,不要纠结于细节
多写小程序练习,形成肌肉记忆
记住 Python 的简洁哲学:代码应该直观易读
善用 Python 的交互式解释器(REPL)快速试验代码
4. 数据结构:从 STL 到 Python 内置类型 Python 的内置数据结构功能强大且易用,相当于 C++ STL 的"开箱即用"版本。本章将帮助你建立 STL 到 Python 的映射关系。
4.1 序列类型
vector vs list (列表) #include <vector>
std::vector<int > numbers;
std::vector<int > nums = {1 , 2 , 3 , 4 , 5 };
std::vector<int > zeros (10 , 0 ) ;
numbers.push_back (10 );
numbers.push_back (20 );
int first = numbers[0 ];
int last = numbers.back ();
numbers.insert (numbers.begin () + 2 , 99 );
numbers.erase (numbers.begin () + 1 );
size_t len = numbers.size ();
bool empty = numbers.empty ();
numbers = []
nums = [1 , 2 , 3 , 4 , 5 ]
zeros = [0 ] * 10
numbers.append(10 )
numbers.append(20 )
first = numbers[0 ]
last = numbers[-1 ]
numbers.insert(2 , 99 )
del numbers[1 ]
numbers.remove(10 )
popped = numbers.pop()
length = len (numbers)
is_empty = len (numbers) == 0
nums = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
nums[2 :5 ]
nums[:3 ]
nums[7 :]
nums[-3 :]
nums[::2 ]
nums[::-1 ]
nums[2 :5 ] = [20 , 30 , 40 ]
std::vector<int > nums = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
std::vector<int > slice (nums.begin() + 2 , nums.begin() + 5 ) ;
std::reverse (nums.begin (), nums.end ());
array vs tuple (元组) #include <array>
std::array<int , 3> point = {1 , 2 , 3 };
int x = point[0 ];
point[1 ] = 5 ;
point = (1 , 2 , 3 )
x = point[0 ]
x, y, z = point
a, b = b, a
def get_coordinates ():
return (10 , 20 , 30 )
x, y, z = get_coordinates()
4.2 关联容器
map vs dict (字典) C++: std::map 和 std::unordered_map
#include <map>
#include <unordered_map>
std::map<std::string, int > scores;
scores["Alice" ] = 95 ;
scores["Bob" ] = 87 ;
scores.insert ({"Charlie" , 92 });
int alice_score = scores["Alice" ];
auto it = scores.find ("David" );
if (it != scores.end ()) {
std::cout << it->second << std::endl;
}
for (const auto & pair : scores) {
std::cout << pair.first << ": " << pair.second << std::endl;
}
std::unordered_map<std::string, int > fast_scores;
scores = {}
scores["Alice" ] = 95
scores["Bob" ] = 87
scores = {"Alice" : 95 , "Bob" : 87 , "Charlie" : 92 }
alice_score = scores["Alice" ]
david_score = scores.get("David" )
david_score = scores.get("David" , 0 )
if "Alice" in scores:
print (scores["Alice" ])
for name, score in scores.items():
print (f"{name} : {score} " )
for name in scores.keys():
print (name)
for score in scores.values():
print (score)
squares = {x: x**2 for x in range (5 )}
set vs set (集合) C++: std::set 和 std::unordered_set
#include <set>
#include <unordered_set>
std::set<int > numbers = {1 , 2 , 3 , 4 , 5 };
numbers.insert (3 );
bool contains = numbers.find (3 ) != numbers.end ();
numbers.erase (2 );
std::set<int > a = {1 , 2 , 3 };
std::set<int > b = {2 , 3 , 4 };
std::set<int > union_set;
std::set_union (a.begin (), a.end (), b.begin (), b.end (), std::inserter (union_set, union_set.begin ()));
numbers = {1 , 2 , 3 , 4 , 5 }
numbers.add(3 )
contains = 3 in numbers
numbers.remove(2 )
numbers.discard(2 )
a = {1 , 2 , 3 }
b = {2 , 3 , 4 }
union = a | b
intersection = a & b
difference = a - b
sym_diff = a ^ b
evens = {x for x in range (10 ) if x % 2 == 0 }
4.3 字符串处理 #include <string>
#include <algorithm>
std::string s = "Hello, World!" ;
int len = s.length ();
s += " Welcome" ;
std::string sub = s.substr (0 , 5 );
size_t pos = s.find ("World" );
if (pos != std::string::npos) {
}
s.replace (7 , 5 , "Python" );
std::transform (s.begin (), s.end (), s.begin (), ::toupper);
s = "Hello, World!"
length = len (s)
s += " Welcome"
sub = s[0 :5 ]
pos = s.find("World" )
contains = "World" in s
s = s.replace("World" , "Python" )
upper = s.upper()
lower = s.lower()
title = s.title()
capitalized = s.capitalize()
words = s.split()
words = s.split(',' )
" " .join(words)
trimmed = s.strip()
left = s.lstrip()
right = s.rstrip()
name = "Alice"
age = 25
msg = f"My name is {name} and I'm {age} years old"
msg = "My name is {} and I'm {} years old" .format (name, age)
msg = "My name is %s and I'm %d years old" % (name, age)
4.4 容器操作
列表推导和生成器
std::vector<int > squares;
for (int i = 0 ; i < 10 ; i++) {
squares.push_back (i * i);
}
std::vector<int > evens;
for (int num : numbers) {
if (num % 2 == 0 ) {
evens.push_back (num);
}
}
#include <ranges>
auto squares = std::views::iota (0 , 10 ) | std::views::transform ([](int x) { return x * x; });
squares = [x**2 for x in range (10 )]
evens = [x for x in numbers if x % 2 == 0 ]
matrix = [[i+j for j in range (3 )] for i in range (3 )]
squares_dict = {x: x**2 for x in range (5 )}
unique_lens = {len (word) for word in words}
squares_gen = (x**2 for x in range (10 ))
常用操作对比
#include <algorithm>
std::vector<int > nums = {3 , 1 , 4 , 1 , 5 , 9 };
std::sort (nums.begin (), nums.end ());
std::sort (nums.begin (), nums.end (), std::greater <int >());
std::sort (nums.begin (), nums.end (), [](int a, int b) { return a > b; });
nums = [3 , 1 , 4 , 1 , 5 , 9 ]
nums.sort()
nums.sort(reverse=True )
sorted_nums = sorted (nums)
sorted_nums = sorted (nums, reverse=True )
words = ["apple" , "pie" , "a" , "zoo" ]
sorted_words = sorted (words, key=len )
sorted_words = sorted (words, key=lambda x: x[-1 ])
#include <algorithm>
auto it = std::find (nums.begin (), nums.end (), 4 );
if (it != nums.end ()) {
size_t index = std::distance (nums.begin (), it);
}
int count = std::count (nums.begin (), nums.end (), 1 );
if 4 in nums:
index = nums.index(4 )
count = nums.count(1 )
4.5 数据结构性能对比 操作 C++ vector Python list C++ map Python dict C++ set Python set 索引访问 O(1) O(1) - - - - 末尾添加 O(1)* O(1)* - - - - 插入/删除 O(n) O(n) O(log n) O(1)* O(log n) O(1)* 查找 O(n) O(n) O(log n) O(1)* O(log n) O(1)* 遍历 O(n) O(n) O(n) O(n) O(n) O(n)
场景 C++ Python 需要快速随机访问 vectorlist需要快速插入/删除 listcollections.deque键值对存储 unordered_mapdict有序键值对 mapcollections.OrderedDict (Python 3.7+ 普通 dict 也保序)去重/集合运算 unordered_setset不可变序列 std::arraytuple优先队列 priority_queueheapq 模块双端队列 dequecollections.deque
4.6 高级数据结构 Python 额外提供的便利工具 (collections模块):
from collections import defaultdict, Counter, deque, namedtuple
word_count = defaultdict(int )
for word in words:
word_count[word] += 1
from collections import Counter
nums = [1 , 2 , 2 , 3 , 3 , 3 , 4 ]
counter = Counter(nums)
print (counter)
most_common = counter.most_common(2 )
dq = deque([1 , 2 , 3 ])
dq.appendleft(0 )
dq.pop()
dq.popleft()
Point = namedtuple('Point' , ['x' , 'y' ])
p = Point(10 , 20 )
print (p.x, p.y)
#include <map>
#include <queue>
std::map<std::string, int > word_count;
for (const auto & word : words) {
word_count[word]++;
}
4.7 推导式专题(Python 独有) Python 的推导式是非常强大且 Pythonic 的特性:
squares = [x**2 for x in range (10 )]
even_squares = [x**2 for x in range (10 ) if x % 2 == 0 ]
result = [x for x in range (20 ) if x % 2 == 0 if x % 3 == 0 ]
pairs = [(x, y) for x in range (3 ) for y in range (3 )]
word_lengths = {word: len (word) for word in ["apple" , "banana" , "cherry" ]}
unique_lengths = {len (word) for word in words}
gen = (x**2 for x in range (1000000 ))
first_ten = [next (gen) for _ in range (10 )]
Python 的数据结构是内置的 ,C++ 需要包含头文件
Python 的操作更简洁 ,如 in 运算符、切片、推导式
Python dict 和 set 基于哈希表 ,通常比 C++ map/set (红黑树) 更快
Python 字符串操作更丰富 ,不需要额外的库或算法
Python 的列表更灵活 ,可以存储不同类型的元素
5. 面向对象:不同的实现方式 C++ 和 Python 都支持面向对象编程,但实现方式有显著差异。
5.1 类的定义 class Person {
private :
std::string name;
int age;
public :
Person (std::string n, int a) : name (n), age (a) {}
~Person () { }
void introduce () {
std::cout << "I'm " << name << ", " << age << " years old" << std::endl;
}
std::string getName () const { return name; }
void setAge (int a) { age = a; }
};
Person p ("Alice" , 25 ) ;
p.introduce ();
class Person :
def __init__ (self, name, age ):
self .name = name
self .age = age
def introduce (self ):
print (f"I'm {self.name} , {self.age} years old" )
p = Person("Alice" , 25 )
p.introduce()
5.2 访问控制 特性 C++ Python 私有成员 private:_name (约定,非强制)保护成员 protected:_name (约定)公有成员 public:默认全部公有 名称改写 无 __name (会改写为 _ClassName__name)
class BankAccount :
def __init__ (self, balance ):
self ._balance = balance
self .__secret = "123"
def deposit (self, amount ):
self ._balance += amount
account = BankAccount(1000 )
print (account._balance)
5.3 属性和装饰器 class Circle {
private :
double radius;
public :
double getRadius () const { return radius; }
void setRadius (double r) { if (r > 0 ) radius = r; }
};
class Circle :
def __init__ (self, radius ):
self ._radius = radius
@property
def radius (self ):
return self ._radius
@radius.setter
def radius (self, value ):
if value > 0 :
self ._radius = value
@property
def area (self ):
return 3.14159 * self ._radius ** 2
c = Circle(5 )
print (c.radius)
c.radius = 10
print (c.area)
5.4 继承 class Animal {
public :
virtual void speak () {
std::cout << "Some sound" << std::endl;
}
virtual ~Animal () {}
};
class Dog : public Animal {
public :
void speak () override {
std::cout << "Woof!" << std::endl;
}
};
class Animal :
def speak (self ):
print ("Some sound" )
class Dog (Animal ):
def speak (self ):
print ("Woof!" )
def bark (self ):
super ().speak()
print ("Bark!" )
class FlyingDog (Dog, Flying):
pass
5.5 特殊方法(魔术方法) class Vector :
def __init__ (self, x, y ):
self .x = x
self .y = y
def __str__ (self ):
return f"Vector({self.x} , {self.y} )"
def __repr__ (self ):
return f"Vector(x={self.x} , y={self.y} )"
def __add__ (self, other ):
return Vector(self .x + other.x, self .y + other.y)
def __len__ (self ):
return int ((self .x**2 + self .y**2 )**0.5 )
def __getitem__ (self, key ):
if key == 0 :
return self .x
if key == 1 :
return self .y
raise IndexError()
v1 = Vector(1 , 2 )
v2 = Vector(3 , 4 )
v3 = v1 + v2
print (v1)
魔术方法 说明 C++ 对应 __init__构造 构造函数 __del__析构 析构函数 __str__字符串表示 operator<<__add__+ 运算符 operator+__eq__== 运算符 operator==__len__len() 函数 size()__getitem__[] 运算符 operator[]__call__() 运算符 operator()
6. 内存管理:从手动到自动
6.1 核心差异 特性 C++ Python 内存分配 手动 new/delete 自动 资源管理 RAII with 语句 垃圾回收 无(需智能指针) 引用计数+GC 内存泄漏 容易发生 很少发生
6.2 上下文管理器 {
std::ifstream file ("data.txt" ) ;
}
with open ('data.txt' ) as file:
content = file.read()
class MyResource :
def __enter__ (self ):
print ("获取资源" )
return self
def __exit__ (self, exc_type, exc_val, exc_tb ):
print ("释放资源" )
return False
with MyResource() as r:
pass
6.3 浅拷贝 vs 深拷贝 import copy
original = [[1 , 2 ], [3 , 4 ]]
shallow = original.copy()
shallow[0 ][0 ] = 99
print (original)
deep = copy.deepcopy(original)
deep[0 ][0 ] = 999
print (original)
7. Python 开发环境:工具链全景
7.1 Python 安装
官方 Python : python.org
Anaconda : 科学计算推荐
Pyenv : 多版本管理
7.2 IDE 和编辑器 工具 特点 适合人群 PyCharm 功能最全,智能提示强 专业开发 VSCode 轻量,插件丰富 通用开发 Jupyter 交互式,数据分析 数据科学
7.3 包管理
pip install requests
pip install -r requirements.txt
pip list
pip uninstall requests
python -m venv myenv
source myenv/bin/activate
pip install numpy
decorate
8. 标准库与生态系统 Python 的"batteries included"(自带电池)哲学意味着标准库功能丰富。
8.1 常用标准库 import os
import pathlib
current_dir = os.getcwd()
os.listdir('.' )
os.path.join('dir' , 'file.txt' )
from pathlib import Path
p = Path('.' )
p.is_file()
p.glob('*.txt' )
files = list (p.iterdir())
from collections import defaultdict, Counter, deque
from itertools import chain, combinations, permutations
from functools import lru_cache, partial
@lru_cache(maxsize=128 )
def fibonacci (n ):
if n < 2 :
return n
return fibonacci(n-1 ) + fibonacci(n-2 )
from datetime import datetime, timedelta
now = datetime.now()
tomorrow = now + timedelta(days=1 )
formatted = now.strftime('%Y-%m-%d %H:%M:%S' )
8.2 必备第三方库 领域 库 用途 HTTP requests HTTP 客户端 测试 pytest 单元测试 数据 pandas, numpy 数据分析 Web django, flask Web 框架 异步 asyncio, aiohttp 异步编程
import requests
response = requests.get('https://api.github.com' )
data = response.json()
response = requests.post('https://api.example.com' , json={'key' : 'value' })
9. 学习路径:从入门到进阶 graph TD
A[开始学习] --> B[第 1 周:基础语法]
B --> C[第 2 周:数据结构]
C --> D[第 3-4 周:OOP 和函数式]
D --> E{选择方向}
E --> F1[Web 开发]
E --> F2[数据科学]
E --> F3[自动化]
F1 --> G1[Django/Flask]
F2 --> G2[Pandas/NumPy]
F3 --> G3[实用脚本]
G1 --> H[持续实践]
G2 --> H
G3 --> H
H --> I[阅读源码]
I --> J[参与开源]
style A fill:#e1f5ff
style H fill:#fff4e1
style J fill:#e1ffe1
学习阶段
语法、数据类型、控制流
列表、字典、集合
函数和模块
10. 最佳实践:写出 Pythonic 代码
10.1 PEP 8 核心要点
class UserAccount :
pass
def get_user_name ():
pass
MAX_SIZE = 100
result = a + b
func(1 , 2 , 3 )
10.2 Pythonic 惯用法
i = 0
while i < len (items):
item = items[i]
process(item)
i += 1
for item in items:
process(item)
result = []
for x in range (10 ):
if x % 2 == 0 :
result.append(x**2 )
result = [x**2 for x in range (10 ) if x % 2 == 0 ]
for i, item in enumerate (items):
print (f"{i} : {item} " )
for name, score in zip (names, scores):
print (f"{name} : {score} " )
11. 常见陷阱:C++ 开发者易犯的错误
陷阱 1: 可变默认参数
def add_item (item, my_list=[] ):
my_list.append(item)
return my_list
print (add_item(1 ))
print (add_item(2 ))
def add_item (item, my_list=None ):
if my_list is None :
my_list = []
my_list.append(item)
return my_list
陷阱 2: 闭包变量绑定
functions = []
for i in range (3 ):
functions.append(lambda : i)
for f in functions:
print (f())
functions = []
for i in range (3 ):
functions.append(lambda x=i: x)
for f in functions:
print (f())
陷阱 3: 字符串拼接性能
for s in strings:
result += s
'' .join(strings)
12. 实战项目建议
项目 1: 文件批处理工具 难度 : ⭐⭐
知识点 : 文件 I/O、os 模块、pathlib
from pathlib import Path
def batch_rename (directory, old_ext, new_ext ):
path = Path(directory)
for file in path.glob(f"*.{old_ext} " ):
new_name = file.stem + f".{new_ext} "
file.rename(file.parent / new_name)
项目 2: Web API 调用工具 难度 : ⭐⭐⭐
知识点 : requests 库、JSON、异常处理
import requests
def get_weather (city ):
url = f"https://api.weather.com/{city} "
response = requests.get(url)
if response.status_code == 200 :
return response.json()
else :
raise Exception(f"Error: {response.status_code} " )
项目 3: 简单 Web 应用 难度 : ⭐⭐⭐⭐
知识点 : Flask 框架、HTML、数据库
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/' )
def home ():
return render_template('index.html' )
if __name__ == '__main__' :
app.run(debug=True )
13. FAQ Q1: Python 比 C++ 慢多少?什么时候性能是问题?
A: Python 通常比 C++ 慢 10-100 倍。但对于大多数应用(Web、数据分析、脚本),开发效率更重要。真正的瓶颈往往是 I/O 或算法,不是语言。需要性能时可以用 Cython 或调用 C++ 模块。
Q2: 应该完全放弃 C++ 吗?
A: 不。两者互补:C++ 适合性能关键代码,Python 适合快速开发和胶水代码。很多项目用 Python 调用 C++ 核心模块。
Q3: Python 适合大型项目吗?
A: 可以。Instagram、Dropbox、YouTube 后端都大量使用 Python。关键是:使用类型提示、写好测试、遵循规范。
Q4: 学 Python 需要多久?
A: 基础:1-2 周;熟练:1-2 月;精通:需要大量实践。有 C++ 基础会快很多。
Q5: 如何在 Python 项目中使用 C++ 代码?
A: 使用 pybind11 或 Cython。示例:
#include <pybind11/pybind11.h>
int add (int a, int b) {
return a + b;
}
PYBIND11_MODULE (example, m) {
m.def ("add" , &add);
}
import example
result = example.add(1 , 2 )
Q6: Python 2 还是 Python 3?
A: 必须 Python 3!Python 2 已于 2020 年停止支持。
Q7: 动态类型会导致更多 bug 吗?
A: 可能。但可以用类型提示+mypy 降低风险。测试比类型系统更重要。
通用:requests, pytest, click
Web:Django, Flask, FastAPI
数据:NumPy, Pandas, Matplotlib
AI:TensorFlow, PyTorch, scikit-learn
print() 调试(快速简单)
pdb 调试器(交互式)
IDE 断点调试(VSCode/PyCharm)
Q10: Python 能做 C++ 能做的所有事吗?
A: 大部分可以,但有限制:
❌ 不适合:实时系统、嵌入式、内核开发
✅ 适合:Web、数据分析、AI、自动化、原型开发
14. 延伸阅读
推荐书籍
《Python Crash Course》- 快速上手
《Automate the Boring Stuff with Python》- 实用导向
《Fluent Python》- 深入理解 Python
《Effective Python》- 最佳实践
《Python Cookbook》- 实用技巧
Web: 《Flask Web Development》
数据:《Python for Data Analysis》
AI: 《Hands-On Machine Learning》
在线资源
Real Python: realpython.com
Python 官方教程
Codecademy Python 课程
LeetCode (Python 刷题)
Project Euler (算法挑战)
HackerRank
开源项目推荐
Requests : HTTP 库,代码优雅
Flask : Web 框架,架构清晰
Django : 大型 Web 框架,学习最佳实践
社区
Stack Overflow (提问)
Reddit r/Python (讨论)
Python Discord (实时交流)
GitHub (阅读源码、参与贡献)
持续学习建议
每天编码 : 形成肌肉记忆
阅读源码 : 学习优秀实践
写博客 : 巩固理解
参与开源 : 实战提升
关注 PEP : 了解语言发展
📚 附录
附录 A:Python 与 C++ 特性对照表 C++ 特性 Python 对应 说明 #includeimport导入模块 namespace模块 命名空间 int, longint整数(无大小限制) float, doublefloat浮点数 charstr字符(Python 无单字符类型) std::stringstr字符串 std::vectorlist动态数组 std::mapdict键值对 std::setset集合 std::pairtuple元组 nullptrNone空值 true/falseTrue/False布尔值 &&and逻辑与 ` ` !not逻辑非 new/delete自动管理 内存管理 virtual默认虚函数 多态 template鸭子类型 泛型 const无(约定用大写) 常量 static@staticmethod静态方法 private:_name私有成员(约定) //注释#注释单行注释 /* */""" """多行注释
附录 B:常用库速查表 requests - HTTP 客户端
pytest - 测试框架
click - 命令行工具
python-dotenv - 环境变量管理
django - 全功能 Web 框架
flask - 轻量 Web 框架
fastapi - 现代异步 API 框架
sqlalchemy - ORM 数据库工具
numpy - 数值计算
pandas - 数据分析
matplotlib - 数据可视化
scikit-learn - 机器学习
jupyter - 交互式笔记本
selenium - 浏览器自动化
pillow - 图像处理
openpyxl - Excel 操作
beautifulsoup4 - HTML 解析
附录 C:学习资源清单
Coursera: Python for Everybody
edX: MIT Introduction to Computer Science
YouTube: Corey Schafer's Python Tutorials
B 站:Python 教程(搜索热门)
Stack Overflow: 技术问答
Reddit r/learnpython: 学习讨论
Python Discord: 实时聊天
知乎 Python 话题:中文社区
🎓 学习建议总结 作为 C++ 开发者学习 Python,你具有得天独厚的优势。记住以下几点:
放下控制欲 - 信任 Python 的自动化,专注业务逻辑
拥抱简洁 - "能一行写完就不用两行"
实践为王 - 每学一个概念立即写代码验证
阅读优秀代码 - GitHub 上找优质 Python 项目学习
参与社区 - 提问、回答、贡献开源
两者并用 - C++ 和 Python 不是替代关系,而是互补
Week 1: 基础语法 → 完成 10 个小练习
Week 2: 数据结构 → 用 Python 重写一个 C++ 项目
Week 3-4: OOP 和高级特性 → 阅读一个开源项目
Month 2: 选择方向深入 → 完成一个实战项目
Month 3 +: 持续实践 → 参与开源、写技术博客
目录
C++ 开发者转 Python:完整学习与实战指南 1. 引言:为什么 C++ 开发者要学 Python 1.1 Python 的应用场景 1.2 学习收益 1.2.1 开发速度提升 Python: 同样的功能 1.2.2 技术栈互补 1.2.3 新的编程视野 2. 思维转换:两种语言的设计哲学 2.1 语言设计哲学对比 C++ 的哲学:"给专家提供工具" Python 的哲学:"简洁优雅" - The Zen of Python 部分输出: Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Readability counts. There should be one-- and preferably only one --obvious way to do it. Python: 简洁就是力量 2.2 编译型 vs 解释型 C++ 开发流程 Python 开发流程 2.3 静态类型 vs 动态类型 静态类型(C++) 动态类型(Python) Python: 变量只是标签,可以指向任何类型 类型提示(Type Hints)- 两者的结合 Python 3.5+: 类型提示(可选) 类型提示不会强制执行! 2.4 内存管理模式 C++: 手动内存管理 + RAII Python: 自动垃圾回收 Python: 完全自动,你不需要关心 2.5 "Pythonic"思维 ❌ 非 Pythonic(C++ 思维写 Python) C++ 思维:使用索引遍历 C++ 思维:手动检查条件 C++ 思维:用 flag 变量 ✅ Pythonic 方式 Pythonic: 直接迭代 Pythonic: 直接判断真值 Pythonic: 使用 in 运算符 Pythonic: 列表推导 vs C++ 风格 Pythonic 的核心原则 示例:交换两个变量 C++ 思维 Pythonic 2.6 思维转换总结 3. 核心语法对比:快速入门 3.1 Hello World 对比 3.2 变量和数据类型 变量声明 直接赋值 类型提示(可选,不强制) 基本数据类型对照表 Python: 整数可以无限大! 类型转换 3.3 控制流 if-else 语句 Python for 循环 方式 1:range 循环(类似 C++ 的索引循环) 方式 2:直接迭代(最 Pythonic) 方式 3:enumerate(需要索引时) 方式 4:带步长的 range Python: range 函数 while 循环 Python 没有 do-while,可以这样模拟 switch vs match (Python 3.10+) 或者使用字典 3.4 函数定义 基本函数 函数定义(无需声明) 调用 带类型提示的版本 默认参数 默认参数直接在定义中 可变参数 *args: 可变位置参数(元组) **kwargs: 可变关键字参数(字典) Lambda 表达式 Python lambda(单行表达式) 自动捕获外部变量 排序中使用 复杂逻辑用 def,不要用 lambda ❌ 不推荐 ✅ 推荐 3.5 命名空间和作用域 命名空间 math_utils.py utils.py main.py from import 别名 作用域规则 LEGB: Local -> Enclosing -> Global -> Built-in Python: 需要声明 global 或 nonlocal 3.6 注释和文档 单行注释 访问文档字符串 3.7 语法对照速查表 3.8 常用操作对比 打印输出 Python 用户输入 Python(更简单) 字符串操作 Python(更方便) 4. 数据结构:从 STL 到 Python 内置类型 4.1 序列类型 vector vs list (列表) 创建和初始化 添加元素 访问元素 插入和删除 大小 Python 独有的强大切片功能 修改切片 array vs tuple (元组) 元组是不可变的 point[1] = 5 # ❌ 错误!元组不可修改 元组解包(非常实用!) 交换变量 函数返回多值 4.2 关联容器 map vs dict (字典) 字典(基于哈希表,Python 3.7+ 保持插入顺序) 访问 安全访问 检查键是否存在 遍历 字典推导(Pythonic!) set vs set (集合) 集合 查找 删除 集合运算(内置!) 集合推导 4.3 字符串处理 基本操作 查找 替换 大小写 分割和连接 去除空白 字符串格式化 4.4 容器操作 列表推导和生成器 列表推导 带条件的推导 嵌套推导 字典推导 集合推导 生成器表达式(节省内存) 不会立即计算,只在迭代时计算 常用操作对比 Python 原地排序 返回新列表 自定义排序键 Python 查找 计数 4.5 数据结构性能对比 4.6 高级数据结构 defaultdict: 带默认值的字典 Counter: 计数器(非常实用!) deque: 双端队列 namedtuple: 命名元组 4.7 推导式专题(Python 独有) 列表推导:基础 列表推导:带条件 列表推导:多重条件 列表推导:嵌套循环 [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)] 字典推导 {'apple': 5, 'banana': 6, 'cherry': 6} 集合推导 生成器表达式(惰性求值) 5. 面向对象:不同的实现方式 5.1 类的定义 使用 5.2 访问控制 Python 相信程序员 5.3 属性和装饰器 使用起来像属性 5.4 继承 多继承 5.5 特殊方法(魔术方法) 6. 内存管理:从手动到自动 6.1 核心差异 6.2 上下文管理器 自定义上下文管理器 6.3 浅拷贝 vs 深拷贝 浅拷贝 深拷贝 7. Python 开发环境:工具链全景 7.1 Python 安装 7.2 IDE 和编辑器 7.3 包管理 pip: Python 标准包管理器 虚拟环境 8. 标准库与生态系统 8.1 常用标准库 os 模块 (传统方式) pathlib (现代方式,推荐) collections: 高级数据结构 itertools: 迭代器工具 functools: 函数工具 8.2 必备第三方库 GET 请求 POST 请求 9. 学习路径:从入门到进阶 学习阶段 10. 最佳实践:写出 Pythonic 代码 10.1 PEP 8 核心要点 ✅ 好的命名 ✅ 空格使用 ✅ 每行不超过 79 字符 10.2 Pythonic 惯用法 ❌ 非 Pythonic ✅ Pythonic ❌ 手动构建列表 ✅ 列表推导 ✅ 使用 enumerate ✅ 使用 zip 11. 常见陷阱:C++ 开发者易犯的错误 陷阱 1: 可变默认参数 ❌ 错误 ✅ 正确 陷阱 2: 闭包变量绑定 ❌ 错误 ✅ 正确 陷阱 3: 字符串拼接性能 ❌ 低效 ✅ 高效 12. 实战项目建议 项目 1: 文件批处理工具 示例:批量重命名文件 项目 2: Web API 调用工具 项目 3: 简单 Web 应用 13. FAQ Python 中调用 14. 延伸阅读 推荐书籍 在线资源 开源项目推荐 社区 持续学习建议 📚 附录 附录 A:Python 与 C++ 特性对照表 附录 B:常用库速查表 附录 C:学习资源清单 🎓 学习建议总结 相关免费在线工具 加密/解密文本 使用加密算法(如AES、TripleDES、Rabbit或RC4)加密和解密文本明文。 在线工具,加密/解密文本在线工具,online
RSA密钥对生成器 生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
Mermaid 预览与可视化编辑 基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
随机西班牙地址生成器 随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online
Gemini 图片去水印 基于开源反向 Alpha 混合算法去除 Gemini/Nano Banana 图片水印,支持批量处理与下载。 在线工具,Gemini 图片去水印在线工具,online
curl 转代码 解析常见 curl 参数并生成 fetch、axios、PHP curl 或 Python requests 示例代码。 在线工具,curl 转代码在线工具,online