Skip to content

Latest commit

 

History

History
42 lines (23 loc) · 1.02 KB

useful_python_tricks.md

File metadata and controls

42 lines (23 loc) · 1.02 KB

🔦Useful Tricks for Python Scripts

🧑‍💻Formatting

Please refer to PEP-8 style guide for consistent, readable, and maintainable code. Use this_is_a_function() for functions and ThisIsAClass for classes. Keep lines under 79 characters and add one blank line between functions.

🌱Environment Management

Create a dedicated Conda environment for each project to avoid version conflicts between packages.

conda create -n myproject python=3.12
conda activate myproject

Use pip install instead of conda install - it minimises the risk of altering other package versions in your environment.

pip install your_package

💬 Comments and Type Hints

Use clear, concise comments to explain logic and context - not just what the code does, e.g.:

def greet(name: str) -> str:
    """Return a polite greeting."""
    return f"Hello, {name}!"
  • Comment as much as possible.
  • Use hints (-> str) to clarify expected input and output.