Comments and Variables of Python

Comments and Variables of Python


A hash sign ( # ) that is not inside a string literal is the beginning of a comment .All characters after the # , up to the end of the physical line, are part of the comment and the Python interpreter ignores them.

# This is a comment

print(“Hello, Python!”)

The above statements will produce the following result:

Hello, Python!

You can type a comment on the same line after a statement or expression as shown below: names ” Prashant ” # This is again comment

Python does not have multiple-line commenting feature.You have to comment each line individually as shown below :

# This is a comment .

# This is a comment , too .

# This is also a comment .

#I said that already .


Variables Variable is a memory space reserved in computer memory to store a value and that value can be further changed if needed. Based on the type of value, the interpreter allocates memory space.

Creating and Using Variables

Python variables do not need explicit declaration to create a variable.The declaration happens automatically when value is assigned to a variable.The equal sign (=) is used to assign values to variables

The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable.

For examples:

age = 23           #Creating an integer variable and assigning integer value to it

price = 45.67         #Creating a floating variable and assigning floating value to it

name = ” Manoj “   #Creating a string variable and assigning string value to it


print(age)                  #printing value of variable age

print(price)               #printing value of variable price

print(name)                #printing value of variable name

Above statements will assign values 23, 45.67 and “Manoj” to variables age, price, and name, respectively and will produce the following output:




Multiple Assignments

Python allows us to assign same value to multiple variables simultaneously. For example, consider the following statement:


The above statement will assign value 1 to all the three variables.

You can also assign different values to multiple variables simultaneously. For example, consider the following statement:

a, b, c = 1,2, “john”

The above statement will create two integer variables a and b and values 1 and 2 will be assigned to the variables a and b respectively and one string variable c and the value “john” is assigned to variable c


Leave a Reply

Your email address will not be published. Required fields are marked *