Lecture
Explaining Code with Comments
Comments are text-based notes within code that are ignored during Python code execution.
Properly used comments make code easier to understand and are often used for documentation to aid collaboration with other developers.
How to Use Comments
In Python, comments are written using the hash (#) symbol. Any text that follows # is treated as a comment.
Writing a Comment
# This line does not affect the execution of the Python code print("Python programming!") # This is also a comment
Multi-line Comments
Python does not directly support multi-line comments, but you can write comments over multiple lines using #.
Additionally, you can use string literals (''' or """) to simulate multi-line comments.
Writing Multi-line Comments
# First line comment # Second line comment """ Triple double-quotes can be used like multi-line comments. However, this is actually a string and affects Python code behavior. """
Lessons in this chapter · Master the Fundamentals of Python
- 1. What is Programming and What Benefits Can You Gain from Learning It?
- 2. Coding and Viewing Your Results in Real-Time
- 3. Are There Levels in Programming Languages?
- 4. Features of Python and Simple Code Example
- 5. Reasons Why Python is Popular
- 6. Why is Indentation Important in Python?
- 7. Printing Output in Python
- 8. Getting User Input in Python
- 9. Multiple-choice quiz
- 10. Statements and Expressions
- 11. Predefined Reserved Words in Python - Keywords
- 12. How to Name Variables and Functions Sensibly
- 13. Explaining Code with Comments
- 14. What are Identifiers?
- 15. A Container for Data, Variables
- 16. Important Points When Assigning Values to Variables
- 17. Symbols for Performing Operations, Operators
- 18. Literals Representing Data
- 19. Coding Quiz - Return 10 Times the Given Number
- 20. Multiple-choice quiz
- 21. Fill-in-the-blank quiz
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help