The Complete Guide to Prompt Engineering: From Zero to Practical Application

A systematic guide to prompt engineering from foundational concepts to Python API development.
This comprehensive guide covers the full prompt engineering learning path: understanding domestic and international LLMs, mastering core techniques like zero-shot/few-shot prompting and chain of thought reasoning, and applying them through Python API development. It provides actionable frameworks for writing effective prompts and choosing the right model for each scenario.
Why You Need to Learn Prompt Engineering
In the era of large models, Prompt Engineering has become an essential skill for every AI user. Whether you want to boost your productivity or leverage AI for side projects, learning how to communicate effectively with large models is an unavoidable first lesson.
As an emerging field, prompt engineering derives its importance from the working mechanisms of Large Language Models (LLMs). LLMs are fundamentally autoregressive models based on the Transformer architecture that generate text by predicting the next token. This means the quality of a model's output is highly dependent on how the input guides it. Research from Stanford University has shown that simply optimizing prompt wording can improve model performance by 20%-50% on certain tasks. Prompt engineering has thus evolved from a collection of empirical tricks into a technical discipline with systematic methodologies, even giving rise to the entirely new job title of "Prompt Engineer."
This article is based on a systematic prompt engineering tutorial, distilling a complete learning path and core knowledge points to help you build a holistic understanding of Prompt Engineering.
Course Architecture: Three Modules, Nine Sections
The tutorial follows a clear design logic, progressing layer by layer from foundational concepts to advanced techniques to hands-on coding, divided into three major modules:
- LLM Awareness Module: Understanding the current landscape and respective strengths of domestic and international large models
- Prompt Engineering Techniques Module: Mastering methodologies for writing high-quality Prompts
- Python Development Hands-on Module: Calling APIs with code to apply prompt engineering in real projects

This "concepts first, practice follows" structural design is commendable — only by truly understanding the core concepts upfront can you get twice the results with half the effort in the Python development sections later.
A Panoramic Survey of Large Models: Choosing Models by Scenario
Why Should You Know About Different Large Models?
Many people think only of ChatGPT when large models come up, but in reality, China has produced a wave of distinctive large model products. The tutorial highlights the following:
- Kimi (Moonshot AI): Outstanding long-text processing capabilities
- 360 AI Brain: Search-enhanced, excellent performance in information retrieval scenarios
- iFlytek Spark: Solid Chinese language comprehension
- ERNIE Bot (Baidu): Mature ecosystem with continuously evolving multimodal capabilities
- Doubao (ByteDance): Smooth conversational experience with high integration
The differentiated characteristics of Chinese large models are closely tied to each company's technical approach and data advantages. For example, Kimi's long-text capability benefits from innovations in its attention mechanism — traditional Transformer attention computation complexity grows quadratically with sequence length, but Kimi uses improved sparse attention and context compression techniques to extend the effective context window to hundreds of thousands of tokens. 360 AI Brain deeply integrates 360 Search Engine's real-time indexing capabilities, employing a RAG (Retrieval-Augmented Generation) architecture that first retrieves the latest information from the internet before generating answers, effectively mitigating the knowledge cutoff date problem and hallucination issues common in large models.
Understanding each model's strengths enables you to "choose models by scenario" in practice, rather than going all-in on a single tool. For instance, choosing Kimi for processing ultra-long documents or 360 AI Brain for real-time information retrieval — this kind of differentiated selection is itself part of prompt engineering.
Core Prompt Engineering Techniques Explained
What Is Prompt Engineering?
Put simply, prompt engineering is a systematic methodology for guiding large models to produce high-quality, expected outputs through carefully designed input text (Prompts). It's not just about "asking questions" — it's a discipline that requires understanding how models work.

Fundamental Prompt Writing Techniques
The tutorial summarizes several key prompt writing techniques:
- Use delimiters: Use symbols like
###,""",'''to clearly separate instructions from content, preventing model confusion - Specify output format: Explicitly tell the model whether you want JSON, Markdown tables, or bullet-point lists
- Role-playing: Having the model assume a specific role (e.g., "You are a senior product manager") can significantly improve the professionalism and relevance of responses
Using delimiters isn't just about making Prompt structure clearer — it's also an important security measure. In real-world applications, if user input isn't clearly separated from system instructions, malicious users could hijack model behavior through "prompt injection attacks" — for example, embedding text like "ignore all previous instructions" in their input. By strictly wrapping user input with triple quotes, XML tags, or other delimiters, the model can better distinguish between the "instruction layer" and the "data layer" — a concept analogous to parameterized queries in SQL injection defense.
The Core Elements Framework for Prompts
The tutorial distills a "Ten Elements" framework for prompt engineering. While the specific details require the full course to learn, the core idea can be summarized as: Role + Task + Context + Format + Constraints. A good Prompt is essentially about being sufficiently clear and specific across these dimensions.
Deep Dive into LLM Reasoning Capabilities
This section contains the highest-value content in the entire tutorial, covering several key prompt engineering concepts:
Zero-shot Prompting
Presenting a task to the model without providing any examples. This tests both the model's generalization ability and whether the Prompt description is precise enough.
Few-shot Prompting
Providing several input-output examples in the Prompt so the model can "follow the pattern." This is one of the most commonly used techniques in practice, especially suited for formatted output, classification tasks, and similar scenarios.
The effectiveness of zero-shot and few-shot prompting is rooted in the "In-Context Learning" capability accumulated during the model's pre-training phase. The GPT-3 paper in 2020 was the first to systematically demonstrate this phenomenon: models can adapt to new tasks without updating parameters, simply by providing a few examples in the Prompt. Subsequent research revealed that this capability likely stems from the vast number of implicit "task-example-answer" patterns in pre-training data. Notably, the selection and ordering of examples in few-shot prompting significantly affects results — research shows that merely changing the order of examples can cause accuracy to swing dramatically from near-random to near-optimal.
Chain of Thought (CoT) Prompting
Whether zero-shot or few-shot, both can be combined with Chain of Thought techniques — guiding the model to "think step by step" rather than jumping straight to a final answer. A simple phrase like "Let's think step by step" can significantly improve model performance on complex reasoning tasks.
Chain of Thought (CoT) prompting was proposed by Jason Wei and colleagues at Google Brain in 2022 and is one of the most impactful breakthroughs in the prompt engineering field. The core finding is that when models are asked to show intermediate reasoning steps, their performance on mathematical reasoning, logical reasoning, and commonsense reasoning tasks improves dramatically. For example, on the GSM8K math benchmark, CoT prompting boosted PaLM 540B's accuracy from 17.9% to 58.1%. A likely explanation is that step-by-step reasoning decomposes complex problems into simpler sub-problems that models handle better, while intermediate steps provide richer contextual information for subsequent reasoning.

Self-Consistency and Tree of Thoughts
- Self-Consistency: Having the model generate multiple reasoning paths for the same problem, then selecting the most frequently occurring answer — similar to a "majority voting" mechanism
- Tree of Thoughts: An extension of Chain of Thought that allows the model to explore multiple branches during reasoning, suitable for complex problems requiring creative solutions
Self-Consistency was proposed by Wang et al. in 2022, inspired by the human cognitive process of trying multiple approaches and cross-validating when solving complex problems. In practice, the model's temperature parameter is typically set to a higher value (e.g., 0.7-1.0) to increase output diversity, generating 5-40 different reasoning paths, with the final answer selected through majority voting. Tree of Thoughts (ToT) was proposed by Yao et al. in 2023, modeling the reasoning process as a search tree where each node represents an intermediate thought state. The model can use breadth-first or depth-first search strategies to explore different branches and backtrack when necessary. ToT performs particularly well on tasks requiring forward planning (such as the Game of 24 and creative writing).
These concepts may sound academic, but understanding them is crucial for writing high-quality Prompts.
Hands-on Python Development with LLM APIs

The final section of the tutorial brings all previous concepts into the Python development environment, practicing various prompt engineering techniques by calling the ChatGPT API.
The core value of this section lies in: transforming manual conversations into programmable, reusable, batch-processable automated workflows. For example, you can use Python scripts to batch-process document summaries, automate customer service responses, build knowledge Q&A systems, and more.
When calling large models through APIs, several core parameters directly affect output quality. temperature controls output randomness, ranging from 0 to 2 — lower values produce more deterministic and conservative outputs, while higher values yield more creative but less controllable results. top_p (nucleus sampling) controls sampling from the subset of highest-probability tokens, and when used in conjunction with temperature, enables fine-grained control over output style. Additionally, max_tokens limits output length, system message sets the model's global behavioral role, and frequency_penalty and presence_penalty control repetition penalties and new topic introduction tendencies, respectively. Understanding the interaction effects of these parameters is a key step in advancing from a Prompt user to a Prompt engineer.
The tutorial emphasizes that the Python hands-on section is essentially a code-based implementation of the earlier concepts, making foundational understanding a prerequisite.
Learning Recommendations for Prompt Engineering
Based on the tutorial's structure, here are some learning recommendations:
- Understand concepts before getting hands-on: Don't rush into writing code — first thoroughly grasp core concepts like zero-shot, few-shot, and chain of thought
- Practice with multi-model comparisons: Test the same Prompt across different large models, observe the differences, and develop "model intuition"
- Build your own Prompt template library: Save effective Prompts categorized by scenario and continuously iterate and optimize them
- Pay attention to Playground debugging mode: ChatGPT's Playground offers more granular parameter controls (such as temperature, top_p, etc.) and is an important tool for advanced learning
Prompt engineering isn't a skill you master overnight — it's a craft that requires continuous refinement through extensive practice. But once you've grasped the right methodological framework, you're already ahead of most people.
Key Takeaways
Related articles

CodeGraph: The 50K-Star Open-Source Tool That Cuts AI Coding Token Usage in Half
CodeGraph is a 50K-star open-source tool that builds a code knowledge graph so AI coding assistants can locate code instantly—cutting Token usage by 47%, boosting speed by 22%, all running 100% locally.

VibeCoding Beginner's Guide: A Complete Guide to Building Software with Natural Language from Scratch
VibeCoding lets anyone build software through natural language conversations with AI. Learn the core concepts, learning path, and practical methods to get started.

Using UU Accelerator to Speed Up Cursor: A Compliant Solution for Stable AI Coding in China
Learn how to use NetEase UU Accelerator to speed up Cursor AI coding tool in China, with step-by-step setup including node selection and launch configuration.