Although comments do not change the outcome of a program, they still play an important role in any programming and not just Python. Comments are the way to improve the readability of a code, by explaining what we have done in code in simple english. In this guide, we will learn about comments in Python and their types.
A comment is text that doesn’t affect the outcome of a code, it is just a piece of text to let someone know what you have done in a program or what is being done in a block of code. This is especially helpful when someone else has written a code and you are analysing it for bug fixing or making a change in logic, by reading a comment you can understand the purpose of code much faster then by just going through the actual code.
There are two types of comments in Python.
In python we use # special character to start the comment. Lets take few examples to understand the usage.
# This is just a comment. Anything written here is ignored by Python
To have a multi-line comment in Python, we use triple single quotes at the beginning and at the end of the comment
''' This is a multi-line comment '''
'\nThis is a \nmulti-line\ncomment\n'
''' We are writing a simple program here First print statement. This is a multiple line comment. ''' print("Hello Guys") # Second print statement print("How are You all?") print("Welcome to BeginnersBook") # Third print statement
Hello Guys How are You all? Welcome to BeginnersBook
Concept: Variables are used to store data, they take memory space based on the type of value we assigning to them. Creating variables in Python is simple, you just have write the variable name on the left side of = and the value on the right side.
Important Points To Understand About Variables - Identifiers
These are the generic rules that you need to follow while creating variables in python.
Variable name is known as identifier.
num = 100 str = "CoderzColumn" print(num) print(str)
x = y = z = 99 print(x) print(y) print(z)
99 99 99
a, b, c = 5, 6, 7 print(a) print(b) print(c)
5 6 7
x = 10 y = 20 print(x + y) p = "Hello" q = "World" print(p + " " + q)
30 Hello World
If you are more comfortable learning through video tutorials then we would recommend that you subscribe to our YouTube channel.
When going through coding examples, it's quite common to have doubts and errors.
If you have doubts about some code examples or are stuck somewhere when trying our code, send us an email at firstname.lastname@example.org. We'll help you or point you in the direction where you can find a solution to your problem.
You can even send us a mail if you are trying something new and need guidance regarding coding. We'll try to respond as soon as possible.
If you want to