Skip to main content

Learning Python Part-6: Python Comments

When it comes to writing a python program, based on the requirements, programs can simple programs of limited number of  lines or it can be really large program which might even span multiple python modules. Now the point here is that, even if we know how to write the program and even we follow correct concepts and syntaxes while writing program, we cannot keep it in our mind forever. We cannot remember each and everything about the program like variables, classes, concepts, functions and so on after some period of time. If the program written by us at some point in time back, once we open it after a period of time, it should not be a situation that we are blank, or guessing why particular code, function and so on. Even it may happen that you are working in a team and program code writing tasks might be shared. So when you put all pieces together written by multiple programmers in your team, you should be able to understand the code. This is where we bring in the concepts of comments in a python programs. They help us to understand how the code is written. There are couple of ways of writing comments python code.
  • Single line comment using # (Hash) symbol:
In Python programs, we use the hash (#) symbol to start writing a comment on single line. Python Interpreter ignores comment. In above example, if you notice, commented text after # symbol is not processed and not displayed as output.
  • Multi-line comment using """  or ''' (Triple qoutes):
If we have comments that extend multiple lines, we can use hash (#) in the beginning of each line, however we have another quick and better option to get this done. Instead of typing # in the beginning of each line, below is the example of how to write multiline comment. In above example, only the print statement text is displayed.

Comments

Popular posts from this blog

Learning Python Part-4: Python Keywords

Python has a set of keywords that are reserved words that cannot be used as variable names, function names, or any other identifiers They are used to define the syntax and structure of the Python language. In Python, keywords are case sensitive. There are 33 keywords in Python 3.7.  All the keywords (except True, False and None) are in lowercase. Below is the list of keywords in Python 3.7 I will not be using just syntax to explain these keywords, rather I will use some simple yet enough code examples considering new plus experienced people. For those who are new to python, if you find it difficult  to understand the complete code, just try to see the context and usage of keyword.  False :  This keyword is used to represent a boolean false. If a statement is false, “False” is printed. False in python equals to 0. True: This keyword is used to represent a boolean true. If a statement is true, “True” is printed. True in python equals to 1. None:

Welcome

Welcome everyone to CodeZen. Learn to code with simplified tutorials and examples.  Our focus will always be on simplicity. Hence all programming tutorials and examples are written in simple, understandable language for everyone including beginners.  The only way to learn to program is by writing code. So we encourage you to try the example we provided, implement your imagination and take it to next level.  We know that there are thousands of resources available on these topics. We just want make difference in how the information is presented so that everyone can understand. We simply want to present a different approach of detailed yet simple, with other - more interesting - examples, and so on.