Python Fundamentals by pluginagentmarketplace/custom-plugin-python
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-python --skill 'Python Fundamentals'本技能涵盖 Python 编程的基础要素,包括语法、数据类型、控制结构、函数、面向对象编程和标准库。
代码示例:
# Type hints and f-strings
def greet_user(name: str, age: int) -> str:
return f"Hello {name}, you are {age} years old!"
# Using the function
message = greet_user("Alice", 30)
print(message) # Hello Alice, you are 30 years old!
代码示例:
# List comprehension with conditional
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_squares = [x**2 for x in numbers if x % 2 == 0]
print(even_squares) # [4, 16, 36, 64, 100]
# Decorator example
def timing_decorator(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"{func.__name__} took {end - start:.4f} seconds")
return result
return wrapper
@timing_decorator
def slow_function():
import time
time.sleep(1)
return "Done!"
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
代码示例:
from abc import ABC, abstractmethod
class Vehicle(ABC):
def __init__(self, brand: str, model: str):
self.brand = brand
self.model = model
@abstractmethod
def start_engine(self) -> str:
pass
def __str__(self) -> str:
return f"{self.brand} {self.model}"
class Car(Vehicle):
def __init__(self, brand: str, model: str, doors: int):
super().__init__(brand, model)
self.doors = doors
def start_engine(self) -> str:
return f"{self} engine started with {self.doors} doors"
# Usage
car = Car("Toyota", "Camry", 4)
print(car.start_engine()) # Toyota Camry engine started with 4 doors
代码示例:
from pathlib import Path
from datetime import datetime, timedelta
from collections import Counter
import json
# Path operations
data_dir = Path("data")
data_dir.mkdir(exist_ok=True)
config_file = data_dir / "config.json"
config = {"app_name": "MyApp", "version": "1.0.0"}
# Write JSON
with open(config_file, "w") as f:
json.dump(config, f, indent=2)
# Read JSON
with open(config_file, "r") as f:
loaded_config = json.load(f)
# Date operations
today = datetime.now()
next_week = today + timedelta(days=7)
formatted = today.strftime("%Y-%m-%d %H:%M:%S")
# Counter for frequency analysis
words = ["apple", "banana", "apple", "cherry", "banana", "apple"]
word_count = Counter(words)
print(word_count.most_common(2)) # [('apple', 3), ('banana', 2)]
构建一个按扩展名组织文件的命令行工具。
要求:
关键技能: pathlib, 文件 I/O, os 模块
使用面向对象原则创建一个联系人管理系统。
要求:
关键技能: OOP, JSON 序列化, 数据结构
分析文本文件的统计信息和模式。
要求:
关键技能: 字符串操作, collections.Counter, CSV
掌握 Python 基础后,继续学习:
每周安装次数
–
代码仓库
GitHub 星标数
5
首次出现时间
–
安全审计
This skill covers the foundational elements of Python programming including syntax, data types, control structures, functions, object-oriented programming, and the standard library.
Code Example:
# Type hints and f-strings
def greet_user(name: str, age: int) -> str:
return f"Hello {name}, you are {age} years old!"
# Using the function
message = greet_user("Alice", 30)
print(message) # Hello Alice, you are 30 years old!
Code Example:
# List comprehension with conditional
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_squares = [x**2 for x in numbers if x % 2 == 0]
print(even_squares) # [4, 16, 36, 64, 100]
# Decorator example
def timing_decorator(func):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print(f"{func.__name__} took {end - start:.4f} seconds")
return result
return wrapper
@timing_decorator
def slow_function():
import time
time.sleep(1)
return "Done!"
Code Example:
from abc import ABC, abstractmethod
class Vehicle(ABC):
def __init__(self, brand: str, model: str):
self.brand = brand
self.model = model
@abstractmethod
def start_engine(self) -> str:
pass
def __str__(self) -> str:
return f"{self.brand} {self.model}"
class Car(Vehicle):
def __init__(self, brand: str, model: str, doors: int):
super().__init__(brand, model)
self.doors = doors
def start_engine(self) -> str:
return f"{self} engine started with {self.doors} doors"
# Usage
car = Car("Toyota", "Camry", 4)
print(car.start_engine()) # Toyota Camry engine started with 4 doors
Code Example:
from pathlib import Path
from datetime import datetime, timedelta
from collections import Counter
import json
# Path operations
data_dir = Path("data")
data_dir.mkdir(exist_ok=True)
config_file = data_dir / "config.json"
config = {"app_name": "MyApp", "version": "1.0.0"}
# Write JSON
with open(config_file, "w") as f:
json.dump(config, f, indent=2)
# Read JSON
with open(config_file, "r") as f:
loaded_config = json.load(f)
# Date operations
today = datetime.now()
next_week = today + timedelta(days=7)
formatted = today.strftime("%Y-%m-%d %H:%M:%S")
# Counter for frequency analysis
words = ["apple", "banana", "apple", "cherry", "banana", "apple"]
word_count = Counter(words)
print(word_count.most_common(2)) # [('apple', 3), ('banana', 2)]
Build a command-line tool that organizes files by extension.
Requirements:
Key Skills: pathlib, file I/O, os module
Create a contact management system using object-oriented principles.
Requirements:
Key Skills: OOP, JSON serialization, data structures
Analyze text files for statistics and patterns.
Requirements:
Key Skills: String manipulation, collections.Counter, CSV
After mastering Python fundamentals, proceed to:
Weekly Installs
–
Repository
GitHub Stars
5
First Seen
–
Security Audits
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
147,400 周安装