Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Commenting out part of a line in Python

Is it possible to comment out part of a line in Python, and not just everything that appears after the "#" until the end of the line?

1 Answer

Cameron Childres
Cameron Childres
11,820 Points

No, # will always comment out everything until the end of the line. Here's the relevant documentation:

A comment starts with a hash character (#) that is not part of a string literal, and ends at the end of the physical line. A comment signifies the end of the logical line unless the implicit line joining rules are invoked. Comments are ignored by the syntax.

And here's a Stack Overflow discussion on the topic, if you're interested.