A variable is nothing but a reserved memory location to store values.
Variables
•
Definition: A variable is nothing but a
reserved memory location to store values.
•
Variable is an entity to which the programmer can assign some values.
Programmers choose the variable name which is meaningful. For example :
•
In the following example we have declared the variable count to which value 10
is assigned with. This value is displayed by passing the variable name to print statement.

In [5]:
count = 10
print(count)
//The variable count
is assigned with value 10 and then using print statement the value is
displayed.
10
We
can re‒declare the variables for assigning different values. For example –

count=10
print(count)
10
count = 1000
print(count)
1000
//The variable count
is initially assigned with 10 and then re‒assigned with the value 1000
Rules for
variable names
•
Variable names must be meaningful. The
variable name normally should denote its purpose. For example ‒ If the variable
name is even_count, then clearly the
total number of even elements is stored in this variable.
• The variable names can be arbitrarily long.
They contain both letters and digits but they cannot start with a number.
•
Normally variable names should start
with lower case letters.
•
The underscore character is allowed in the variable name. For example ‒ int
total_elements.
Example:1
Evaluate
the following expressions in python
24//6%3
float(4+int(2.39)%2)
2**2**3
Solution :
i)
1
ii)
4.0
iii)
256
Python for Data Science: Chapter 1: Basics of Python : Tag: Computer Programming, Python, Data Science : - Variables in Python
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science - Laboratory
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation