Variable in Python

The term "variable" in Python refers to a named location in memory where data can be stored and manipulated. Variables in Python are dynamically typed, meaning you don’t need to declare their type explicitly—it is inferred based on the value assigned.

Example
x = 5
y = 12.0
z = "Vikas"
print(x)
print(y)
print(z)
x = 2
y = 3.0
z = "Small Code"
print(x)
print(y)
print(z)
Output
5
12.0
Vikas
2
3.0
Small Code

Comments

Comments in Python are notes written within the code to make it more understandable. They are ignored by the Python interpreter. There are two types of comments:

  • Single-line Comments
  • Multiline Comments

Single-line Comments

Single-line comments start with a # and continue until the end of the line.

# This is a single-line comment
x = 5  # Variable declaration
print(x)
Example
x = 5
# y = "Vikas"
z = "SmallCode"
print(x)
# print(y)
print(z)
Output
5
SmallCode

Multiline Comments

Multiline comments are written between """ or ''' and can span multiple lines.

"""
This is a
multiline comment
"""
Example
"""
x = 5
y = "Vikas"
"""
z = "SmallCode"
print(z)
Output
SmallCode