Comments#
Introduction#
Comments in Python are used to add explanations or notes within the code. They do not affect how the code runs and are useful for clarifying logic, documenting functionality, or temporarily disabling parts of the code.
Comments#
A single-line comment starts with #
(spoken as “hash”) and continues until the end of the line.
def main():
# This is a single-line comment
console.print("Hello!") # Print a greeting message
# Start threads — Do not delete
start_thread(main)
def main():
# Print a greeting and then a farewell
console.print("Hello!")
console.new_line()
console.print("Goodbye!")
# Start threads — Do not delete
start_thread(main)
Multiline String Comments#
Triple-quoted string comments (“”” “””
or ‘’’ ‘’’
) can be used for multiline explanations. Although they are technically string objects, they can function as comments if not assigned to a variable.
def main():
"""
This project prints a greeting message,
followed by a farewell message
"""
console.print("Hello!")
console.new_line()
console.print("Goodbye!")
# Start threads — Do not delete
start_thread(main)