Updated On : May-05,2020 Time Investment : ~10 mins

Python Programming Guide For Beginners - Part 3

Learning About Python Comments

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.

Types of Comments in Python

There are two types of comments in Python.

  1. Single line comment
  2. Multiple line comment

Single line comment

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

Multi-line comment:

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'

Simple Program To Understand The Use Of Comments In Python

'''
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

Understanding Python Variables

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.

  1. The name of the variable must always start with either a letter or an underscore (_). For example: _str, str, num, _num are all valid name for the variables.
  2. The name of the variable cannot start with a number. For example: 9num is not a valid variable name.
  3. The name of the variable cannot have special characters, they can only have alphanumeric characters and underscore (A to Z, a to z, 0-9 or _ ).
  4. Variable name is case sensitive in Python which means num and NUM are two different variables in python.

Simple Program For Understanding Variables - Identifiers In Python

num = 100
str = "CoderzColumn"
print(num)
print(str)
100
CoderzColumn

Program For Multiple Assignment - Variables In Python

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

Understanding Concatenation Operation On The Variables

x = 10
y = 20
print(x + y)

p = "Hello"
q = "World"
print(p + " " + q)
30
Hello World
Dolly Solanki  Dolly Solanki

YouTube Subscribe Comfortable Learning through Video Tutorials?

If you are more comfortable learning through video tutorials then we would recommend that you subscribe to our YouTube channel.

Need Help Stuck Somewhere? Need Help with Coding? Have Doubts About the Topic/Code?

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 coderzcolumn07@gmail.com. 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.

Share Views Want to Share Your Views? Have Any Suggestions?

If you want to

  • provide some suggestions on topic
  • share your views
  • include some details in tutorial
  • suggest some new topics on which we should create tutorials/blogs
Please feel free to contact us at coderzcolumn07@gmail.com. We appreciate and value your feedbacks. You can also support us with a small contribution by clicking DONATE.


Subscribe to Our YouTube Channel

YouTube SubScribe

Newsletter Subscription