CopilotHub
SearchPromptsInstructionsAgentsToolsMCPs
  1. Home
  2. Instructions
  3. Python Coding Conventions
Back to Instructions

Python Coding Conventions

Coding standards for python.instructions

python
1 downloads
59 views
0

Tags

testing
best-practices
documentation

Related Instructions

View all →

Python Docstring Standards

*.py

Write clear and consistent Python docstrings

python
python
documentation
+1
1
117

TypeScript Error Handling

*.ts

Comprehensive error handling patterns for TypeScript applications

typescript
typescript
error-handling
+1
0
101

React Component Best Practices

*.tsx

Guidelines for creating maintainable and performant React components

typescript
react
react
typescript
+2
0
116

WordPress Development — Copilot Instructions

Coding standards for wordpress.instructions

typescript
testing
security
+5
1
185

VueJS 3 Development Instructions

Coding standards for vuejs3.instructions

typescript
react
testing
security
+6
0
157

TypeScript MCP Server Development

Coding standards for typescript mcp server.instructions

typescript
express
testing
security
+5
0
126
Browse More Instructions

CopilotHub

A curated collection of prompts, instructions, agents, and tools for AI-powered development.

Quick Links

  • Prompts
  • Instructions
  • Agents
  • Tools
  • MCPs
  • Search

Browse by Category

  • Code Generation
  • Debugging
  • Documentation
  • Refactoring
  • Testing
  • Security

Legal

  • Guidelines
  • About
  • Privacy Policy
  • Terms of Service

Community

GitHub

© 2026 CopilotHub.

Python Coding Conventions

Python Instructions

  • Write clear and concise comments for each function.
  • Ensure functions have descriptive names and include type hints.
  • Provide docstrings following PEP 257 conventions.
  • Use the typing module for type annotations (e.g., List[str], Dict[str, int]).
  • Break down complex functions into smaller, more manageable functions.

General Instructions

  • Always prioritize readability and clarity.
  • For algorithm-related code, include explanations of the approach used.
  • Write code with good maintainability practices, including comments on why certain design decisions were made.
  • Handle edge cases and write clear exception handling.
  • For libraries or external dependencies, mention their usage and purpose in comments.
  • Use consistent naming conventions and follow language-specific best practices.
  • Write concise, efficient, and idiomatic code that is also easily understandable.

Code Style and Formatting

  • Follow the PEP 8 style guide for Python.
  • Maintain proper indentation (use 4 spaces for each level of indentation).
  • Ensure lines do not exceed 79 characters.
  • Place function and class docstrings immediately after the def or class keyword.
  • Use blank lines to separate functions, classes, and code blocks where appropriate.

Edge Cases and Testing

  • Always include test cases for critical paths of the application.
  • Account for common edge cases like empty inputs, invalid data types, and large datasets.
  • Include comments for edge cases and the expected behavior in those cases.
  • Write unit tests for functions and document them with docstrings explaining the test cases.

Example of Proper Documentation

python
def calculate_area(radius: float) -> float:
    """
    Calculate the area of a circle given the radius.
    
    Parameters:
    radius (float): The radius of the circle.
    
    Returns:
    float: The area of the circle, calculated as π * radius^2.
    """
    import math
    return math.pi * radius ** 2