Source code is the human-readable text from which programs are built. It is the version developers edit, review, and keep under version control.
Understanding the Concept
A Python source file often ends in .py and may contain comments, variable assignments, function definitions, and executable statements. Python is sensitive to its syntax: punctuation, indentation, and spelling can change the meaning of the file. Comments explain intentions to people; they are not executed as instructions. The code itself should be readable enough that future developers can understand and update it.
When and Why You Would Use This
Imagine revisiting a program next month. Descriptive names and a short comment about a business rule will help you understand why the code exists. The interpreter does not care whether you use a long or short descriptive name, but readers do.
Practical Example
# The delivery fee is charged once per order.
product_total = 45
delivery_fee = 6
order_total = product_total + delivery_fee
print("Amount due:", order_total)
Understanding the Example
The comment explains the intent of a business rule. Python ignores it when running the file. The remaining lines calculate 51. The file is source code because you can open it, read it, and make changes without rebuilding a special binary executable.
Example Output
Amount due: 51
Try It Yourself
Rename one variable to make its meaning clearer. Add a comment explaining why the delivery fee is applied.
Common Beginner Mistakes
- Thinking comments execute instructions. Lines beginning with # are ignored as comments.
- Keeping the only copy of your work in a temporary console history. Save reusable code in a .py file.
- Using unclear names or copying old comments that no longer match the code. Both make future changes risky.
Key Takeaways
- Source code is the editable, readable definition of program behavior.
- Python files commonly use the .py extension.
- Readable names and accurate comments help people maintain the program.