What symbol is used for comments in Python?

Study for the WGU C173 Scripting and Programming Test. Dive into coding challenges and multiple-choice questions with expert explanations. Prepare thoroughly and excel!

In Python, the symbol used for single-line comments is the hash symbol, or pound sign, represented as '#'. When this symbol precedes text on a line, Python interprets everything following it as a comment. Comments are crucial in programming because they allow developers to annotate their code, making it easier to understand the purpose of specific sections or to provide additional context for future reference.

For example:


# This is a single-line comment in Python

print("Hello, World!")  # This prints 'Hello, World!'

In the context of the incorrect options, /* is used in languages like C and Java for multi-line comments. The double dash (--) is typically used for comments in SQL, and // is utilized for single-line comments in languages such as C++, Java, and JavaScript. These symbols are not applicable in Python, making the hash symbol the correct choice for indicating comments in Python code.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy