
This is good practice for any programmer.
Comment on your code as much as possible. Still, there are some general best practices: An interpreter entirely ignores comments within code. The best practices for commenting on Python codeĬommenting on Python code is done purely for the sake of readability. There aren’t significant downsides to using this type of code, but it may not always maintain compatibility with future versions of Python and, therefore, may not be something that a developer wants to lean on. It’s not intended behavior, even if it’s used that way. Many developers do this, but you really shouldn’t. So, you can write something like this: “”” Python ignores things called “string literals,” which is anything that’s between triple quotes. In Python, you have to comment out each individual line to do multiple lines or block comments: #Multipleīut there is one exception, although it’s a little messy. Inline comments are the most common types of comments. This is great for commenting out large blocks of code because you’re able to comment and uncomment code without having to go line by line. In Javascript, for instance, you can comment in two ways: #single-line Python doesn’t actually have an internal syntax for multi-line comments in the way that people are used to. It’s going to print nothing because it’s commented out. The above Python round() function is not going to actually work. You can also comment out code this way: #round(1.234) Similarly, you can use this along with other codes: print(“Hello, world!”) #This prints Hello, world! The comment starts directly at the symbol: #A single line comment in Python. A single-line comment uses a hash character (#), also known as a pound symbol.
The easiest comment in Python is the single line comment. Learn Python like a Professional Start from the basics and go all the way to creating your own applications and games | By Jose Portilla Explore Course Single line comments in Python