CBSE Class 12 Computer Science Question 105 of 120

Review of Python Basics — Question 57

Back to all questions
57
Question

Question 51

What are comments in Python? How is a comment different from indentation?

Answer

Comments in Python are additional information provided alongside a statement or a chunk of code to enhance the clarity of the code. They begin with the '#' symbol in Python and extend until the end of the line for single-line comments. For multi-line comments, Python supports using triple quotes (''' or """) to enclose the comment text. They are entirely ignored by the Python interpreter during program execution and are used solely for documentation and explanation purposes.
Indentation, on the other hand, defines the structure and hierarchy of code blocks. It indicates the beginning and end of loops, conditional statements, function definitions, and other blocks of code. Indentation refers to the spaces or tabs placed at the beginning of lines of code to signify blocks. Proper indentation is crucial for the interpreter to comprehend the structure of the code. Incorrect or inconsistent indentation can lead to syntax errors or alter the logic of the program.