CodeLangs AISoftware Training Institute
Python for Beginners (Marathi)/Python Variables
Dashboard
Chapter 4 · Python Fundamentals

Python Variables

2,621
words
12
min read
32
practice items
Interactive learning

Practice lab

Question 1 of 12 00:00

Python program मध्ये data वापरताना त्या data ला meaningful नाव देण्याची गरज असते. त्या नावामुळे आपण value पुन्हा वापरू शकतो, बदलू शकतो आणि program अधिक readable बनवू शकतो. या chapter मध्ये variable म्हणजे काय, variable कसा create करायचा, value assign/reassign कशी करायची, multiple assignment, variable naming rules आणि naming conventions शिकणार आहोत.

या examples साठी Python 3.14 stable series लागू आहे. 7 September 2026 रोजी Python 3.14.7 ही latest stable Python 3 release आहे.


Learning Outcomes#

हा chapter पूर्ण केल्यानंतर तुम्ही independently:

  • variable म्हणजे काय हे explain करू शकाल.
  • Python मध्ये variable create करून value assign करू शकाल.
  • existing variable ची value reassign करू शकाल.
  • एकाच statement मध्ये multiple variables assign करू शकाल.
  • valid आणि invalid variable names ओळखू शकाल.
  • Python चे case-sensitive naming behavior समजू शकाल.
  • naming rules आणि naming conventions मधला फरक सांगू शकाल.
  • readable snake_case variable names लिहू शकाल.
  • variable-related common syntax आणि runtime mistakes diagnose करू शकाल.
  • basic variable interview questions confidently answer करू शकाल.

What is a Variable?#

कल्पना करा की application मध्ये student चे नाव वापरायचे आहे.

आपण प्रत्येक ठिकाणी थेट "Sneha" लिहू शकतो.

PYTHON
print("Sneha")
print("Sneha")
print("Sneha")

पण उद्या student चे नाव बदलले तर प्रत्येक ठिकाणी value manually बदलावी लागेल.

याऐवजी:

PYTHON
student_name = "Sneha"

print(student_name)
print(student_name)
print(student_name)

आता "Sneha" या value ला आपण student_name हे meaningful नाव दिले आहे.

Definition

A variable is a name that refers to a value in a program.

मराठी अर्थ

Variable म्हणजे program मधील एखाद्या value ला दिलेले नाव.

उदाहरण:

PYTHON
course_name = "Python Beginner Course"

इथे:

TEXT
course_name          =          "Python Beginner Course"
    ↓                 ↓                    ↓
variable name     assignment             value
                  operator

महत्त्वाचे: Beginner level वर variable ला "value ठेवण्याचा box" असे समजणे सोपे वाटू शकते, पण Python मध्ये अधिक अचूक समज अशी आहे:

Variable name एका value/object कडे refer करते.

Python documentation assignment ला name आणि value यांच्यात binding/rebinding म्हणून describe करते.


Why Do We Need Variables?#

Suppose तुम्ही course enrollment system तयार करत आहात.

तुमच्याकडे खालील information आहे:

PYTHON
student_name = "Aarav"
course_name = "Python Beginner Course"
progress = 20

आता application मध्ये meaningful names वापरल्यामुळे code लगेच समजतो.

Compare:

PYTHON
x = "Aarav"
y = "Python Beginner Course"
z = 20

आणि:

PYTHON
student_name = "Aarav"
course_name = "Python Beginner Course"
progress = 20

दुसरा code अधिक readable आहे.

Variables मुळे आपण:

  • values ला meaningful names देऊ शकतो
  • values पुन्हा वापरू शकतो
  • values बदलू शकतो
  • code readable ठेवू शकतो
  • program state represent करू शकतो

Creating Variables#

Definition

A variable is created when a value is assigned to a name.

मराठी अर्थ

एखाद्या नावाला value assign केली की Python मध्ये त्या नावाचा variable तयार होतो.

Python मध्ये basic variable तयार करण्यासाठी Java सारखी separate declaration आवश्यक नाही.

PYTHON
student_name = "Riya"

इथे student_name या नावाला "Riya" value assign झाली.

आता:

PYTHON
print(student_name)

Expected Output:

TEXT
Riya

आणखी examples#

PYTHON
city = "Pune"
experience = 2
course_completed = False

या chapter मध्ये आपण values चे वेगवेगळे data types खोलात शिकणार नाही. ते Python Data Types chapter मध्ये शिकू.


Variable Creation Flow#

TEXT
student_name = "Riya"
        │
        ▼
Right-side value is evaluated
        │
        ▼
"Riya"
        │
        ▼
The name student_name is bound to that value
        │
        ▼
student_name can now be used

उदाहरण:

PYTHON
student_name = "Riya"
print(student_name)

Assigning Values#

Definition

Assignment connects a variable name with a value.

मराठी अर्थ

Assignment म्हणजे variable च्या नावाला value जोडणे.

Python मध्ये basic assignment साठी = वापरतो.

PYTHON
city = "Mumbai"

इथे:

  • city → variable name
  • = → assignment operator
  • "Mumbai" → assigned value

आणखी example#

PYTHON
employee_name = "Rahul"
employee_id = 105
office = "Pune"

print(employee_name)
print(employee_id)
print(office)

Expected Output:

TEXT
Rahul
105
Pune

Assignment करताना Execution Order#

हे statement बघा:

PYTHON
username = "Neha"

Conceptually Python:

  1. right side ची value evaluate करतो
  2. त्या value ला username नाव bind करतो
  3. त्यानंतर username वापरता येतो

म्हणून:

PYTHON
print(username)

हे assignment नंतर valid आहे.

पण:

PYTHON
print(username)
username = "Neha"

या वेळी पहिल्या line वर username अजून defined नसेल तर NameError होईल.


Reassigning Values#

Real application मध्ये values नेहमी permanent नसतात.

उदाहरण:

Student ची course progress सुरुवातीला:

PYTHON
progress = 10

नंतर:

PYTHON
progress = 40

आता progress ची current value 40 आहे.

Definition

Reassignment means binding an existing variable name to a new value.

मराठी अर्थ

Existing variable ला नवीन value assign करणे म्हणजे reassignment.

उदाहरण:

PYTHON
city = "Pune"

print(city)

city = "Mumbai"

print(city)

Expected Output:

TEXT
Pune
Mumbai

काय झाले?#

TEXT
Initially:

city ─────► "Pune"

After:

city ─────► "Mumbai"

city = "Mumbai" हे statement previous assignment replace करते.


Reassignment in a Real Scenario#

Suppose user ने delivery address change केला.

PYTHON
delivery_city = "Pune"

print(delivery_city)

delivery_city = "Nagpur"

print(delivery_city)

Expected Output:

TEXT
Pune
Nagpur

Application च्या current state नुसार variable ची value बदलू शकते.


Same Variable, Different Values#

Python मध्ये variable लिहिताना त्याचा type declare करावा लागत नाही.

उदाहरण:

PYTHON
value = 100
value = "Completed"

हे Python मध्ये allowed आहे.

पण values चे types, type checking आणि type() पुढच्या Python Data Types chapter मध्ये detail मध्ये शिकू.


Multiple Assignment#

कधी कधी आपल्याला अनेक variables create करायचे असतात.

Python यासाठी convenient assignment syntax देते.


Assign Different Values to Multiple Variables#

Definition

Multiple assignment allows multiple variable names to receive values in one statement.

मराठी अर्थ

एका statement मध्ये अनेक variables ला values assign करता येतात.

उदाहरण:

PYTHON
name, city, country = "Asha", "Pune", "India"

हे conceptually:

PYTHON
name = "Asha"
city = "Pune"
country = "India"

यासारखे आहे.

Use:

PYTHON
name, city, country = "Asha", "Pune", "India"

print(name)
print(city)
print(country)

Expected Output:

TEXT
Asha
Pune
India

Values position नुसार variables ला assign होतात.

TEXT
name       city       country
  ↑          ↑           ↑
"Asha"     "Pune"      "India"

Assign Same Value to Multiple Variables#

जर अनेक variables ना same value द्यायची असेल:

PYTHON
x = y = z = 0

नंतर:

PYTHON
print(x)
print(y)
print(z)

Expected Output:

TEXT
0
0
0

हे syntax initialization सारख्या simple cases मध्ये useful असू शकते.


Swapping Two Variables#

Python मध्ये दोन variables च्या values सहज exchange करता येतात.

PYTHON
first = "Tea"
second = "Coffee"

first, second = second, first

print(first)
print(second)

Expected Output:

TEXT
Coffee
Tea

Before:

TEXT
first  → Tea
second → Coffee

After:

TEXT
first  → Coffee
second → Tea

Temporary variable manually create करण्याची गरज नाही.


Number of Variables and Values Must Match#

हे valid आहे:

PYTHON
x, y = 10, 20

पण:

PYTHON
x, y = 10, 20, 30

या assignment मध्ये left side वर दोन targets आणि right side वर तीन values आहेत.

Beginner level वर लक्षात ठेवा:

Simple multiple assignment मध्ये variables आणि supplied values योग्य प्रकारे match झाले पाहिजेत.

Advanced unpacking पुढील योग्य chapter मध्ये शिकता येईल.


Variable Naming Rules#

Variable name लिहिण्यासाठी Python चे काही language rules आहेत.

Definition

Variable naming rules define which names are syntactically valid Python identifiers.

मराठी अर्थ

Python मध्ये कोणती variable names technically valid आहेत हे naming rules ठरवतात.

Python identifiers मध्ये letters, underscore आणि digits वापरता येतात; digit पहिल्या character म्हणून वापरता येत नाही. Names case-sensitive आहेत आणि reserved keywords ordinary identifiers म्हणून वापरता येत नाहीत.


Rule 1 — Name Cannot Start With a Digit#

Valid:

PYTHON
student1 = "Amit"
course2 = "Python"

Invalid:

PYTHON
1student = "Amit"
2course = "Python"

Better:

PYTHON
student1 = "Amit"
course2 = "Python"

Rule 2 — Letters, Digits and Underscore Can Be Used#

Valid:

PYTHON
student_name = "Sneha"
student2 = "Rahul"
_score = 80

Python technically supports a wider range of Unicode identifiers too, but production code मध्ये simple readable ASCII English names वापरणे beginner साठी अधिक practical आहे.


Rule 3 — Spaces Are Not Allowed Inside a Variable Name#

Invalid:

PYTHON
student name = "Asha"

Correct:

PYTHON
student_name = "Asha"

Underscore शब्द वेगळे करण्यासाठी useful आहे.


Rule 4 — Hyphen Is Not Used as Part of a Variable Name#

Invalid:

PYTHON
student-name = "Asha"

Correct:

PYTHON
student_name = "Asha"

- हा variable-name separator नाही.


Rule 5 — Python Keywords Cannot Be Ordinary Variable Names#

Invalid:

PYTHON
class = "Beginner"

Invalid:

PYTHON
for = 10

class आणि for Python keywords आहेत.

Correct:

PYTHON
course_level = "Beginner"
loop_count = 10

Rule 6 — Variable Names Are Case-Sensitive#

हे तीन different names आहेत:

PYTHON
name = "Asha"
Name = "Rahul"
NAME = "Neha"

Example:

PYTHON
city = "Pune"
City = "Mumbai"

print(city)
print(City)

Expected Output:

TEXT
Pune
Mumbai
city आणि City same variable नाहीत.

Rule 7 — Special Symbols Should Not Be Used in Ordinary Variable Names#

Invalid examples:

PYTHON
$user = "Asha"
user@name = "Asha"
total% = 50

Use:

PYTHON
user = "Asha"
user_name = "Asha"
total_percentage = 50

Naming Rules vs Naming Conventions#

हा distinction खूप important आहे.

Naming Rule#

Rule break केला तर code invalid होऊ शकतो.

PYTHON
2student = "Asha"

हे invalid आहे.

Naming Convention#

Convention break केली तरी code run होऊ शकतो, पण code quality कमी होऊ शकते.

उदाहरण:

PYTHON
studentName = "Asha"

हे Python मध्ये valid असू शकते.

पण सामान्य Python style:

PYTHON
student_name = "Asha"

म्हणून:

Rules decide whether a name is valid. Conventions help make a valid name readable and consistent.

Naming Conventions#

Use snake_case for Normal Variable Names#

Definition

snake_case writes lowercase words separated by underscores.

मराठी अर्थ

अनेक शब्दांच्या variable name मध्ये lowercase words underscore ने वेगळे लिहिण्याची style म्हणजे snake_case.

Examples:

PYTHON
student_name = "Ravi"
course_name = "Python"
total_marks = 450
delivery_city = "Pune"

PEP 8 recommends lowercase variable names with underscores between words when needed for readability.


Use Meaningful Names#

Weak:

PYTHON
x = "Python Beginner Course"

Better:

PYTHON
course_name = "Python Beginner Course"

Weak:

PYTHON
p = 999

Better:

PYTHON
course_price = 999

Reader ला code समजण्यासाठी guess करावे लागू नये.


Avoid Unnecessarily Long Names#

Too vague:

PYTHON
x = "Pune"

Too long:

PYTHON
the_city_where_the_student_currently_lives = "Pune"

Better:

PYTHON
student_city = "Pune"

Goal:

Clear + concise + meaningful


Avoid Confusing Single-Letter Names#

PEP 8 specifically discourages l, O आणि I single-character names कारण काही fonts मध्ये ते 1 किंवा 0 सारखे दिसू शकतात.

Weak:

PYTHON
l = 10
O = 20
I = 30

Better:

PYTHON
length = 10
order_count = 20
item_count = 30

Do Not Shadow Important Built-in Names Without a Good Reason#

Python मध्ये काही useful built-in names आहेत.

उदाहरण:

PYTHON
list = "Students"

हे काही contexts मध्ये syntactically valid असू शकते, पण आता list नावाचा built-in वापरताना confusion निर्माण होऊ शकतो.

Better:

PYTHON
student_list_name = "Students"

Similarly avoid careless names such as:

PYTHON
str = "Hello"
type = "premium"
sum = 100

जर तुम्हाला ते built-ins म्हणून नंतर वापरायचे असतील तर अशा naming मुळे problem निर्माण होऊ शकतो.


Constants: UPPER_CASE Convention#

Python language normal variables सारखीच assignment वापरते, पण project मध्ये "ही value बदलू नये" असा developer intent दाखवण्यासाठी constants साठी uppercase convention वापरली जाते.

PYTHON
MAX_ATTEMPTS = 3
DEFAULT_LANGUAGE = "Marathi"

हा language enforcement rule नाही; ही naming convention आहे.


Practical / Real-World Application#

Scenario: Course Enrollment#

Suppose तुम्ही online learning application बनवत आहात.

New enrollment साठी:

PYTHON
student_name = "Sneha"
course_name = "Python Beginner Course"
course_status = "Not Started"
progress = 0

User course सुरू करतो.

PYTHON
course_status = "In Progress"
progress = 15

Complete example:

PYTHON
student_name = "Sneha"
course_name = "Python Beginner Course"
course_status = "Not Started"
progress = 0

print(student_name)
print(course_name)
print(course_status)
print(progress)

course_status = "In Progress"
progress = 15

print(course_status)
print(progress)

Expected Output:

TEXT
Sneha
Python Beginner Course
Not Started
0
In Progress
15

इथे आपण:

  • meaningful variables तयार केले
  • initial values assign केल्या
  • बदललेली application state reassign केली
  • consistent naming convention वापरली

Another Practical Example: Delivery Details#

PYTHON
customer_name = "Rohan"
delivery_city = "Pune"
delivery_status = "Pending"

print(customer_name)
print(delivery_city)
print(delivery_status)

delivery_city = "Mumbai"
delivery_status = "Confirmed"

print(delivery_city)
print(delivery_status)

Expected Output:

TEXT
Rohan
Pune
Pending
Mumbai
Confirmed

यामुळे variable फक्त academic concept नसून application state represent करण्यासाठी fundamental आहे हे दिसते.


Common Mistakes & Misconceptions#

Misconception 1 — "Variable म्हणजे permanently fixed value"#

का believable वाटते?

कारण आपण variable create करताना एक value assign करतो.

पण:

PYTHON
status = "Pending"
status = "Completed"

Correct understanding:

Variable name पुन्हा दुसऱ्या value ला bind होऊ शकते.

Misconception 2 — "= म्हणजे mathematical equality"#

Programming assignment मध्ये:

PYTHON
score = 100

याचा अर्थ:

score ला 100 assign करा.

हे mathematical equation solve करणे नाही.

Comparison operations आपण appropriate पुढील chapter मध्ये शिकू.


Misconception 3 — "Variable वापरण्याआधी declaration line आवश्यक आहे"#

Python basic assignment मध्ये:

PYTHON
name = "Asha"

हेच name create/bind करण्यासाठी पुरेसे आहे.

Separate:

TEXT
declare name

अशी ordinary beginner syntax नाही.


Misconception 4 — "userName invalid आहे कारण Python snake_case वापरतो"#

userName syntax च्या दृष्टीने valid असू शकते.

पण:

PYTHON
user_name

हे Python naming convention ला अधिक consistent आहे.

Rule आणि convention confuse करू नका.


Misconception 5 — name आणि Name Same आहेत#

Wrong.

PYTHON
name = "Riya"
Name = "Aarav"

हे दोन वेगळे identifiers आहेत.


Misconception 6 — कोणतेही readable word variable म्हणून वापरता येते#

नाही.

PYTHON
class = "Python"

class reserved keyword असल्यामुळे ordinary variable name म्हणून वापरता येत नाही.


Hands-On Practice#

Practice 1 — Create Meaningful Variables#

Requirement#

खालील student information variables मध्ये store करा:

  • name = Anaya
  • city = Pune
  • course = Python

Learner Task#

Meaningful snake_case names वापरा आणि values print करा.

Hint 1#

Assignment syntax:

TEXT
variable_name = value

Hint 2#

तीन separate variables create करा.

Solution#

PYTHON
student_name = "Anaya"
student_city = "Pune"
course_name = "Python"

print(student_name)
print(student_city)
print(course_name)

Expected Output:

TEXT
Anaya
Pune
Python

Practice 2 — Reassign a Status#

Requirement#

Initial order status "Pending" आहे. नंतर ते "Shipped" करा.

Learner Task#

एकच variable वापरा.

Hint#

Existing name ला पुन्हा value assign करा.

Solution#

PYTHON
order_status = "Pending"
print(order_status)

order_status = "Shipped"
print(order_status)

Expected Output:

TEXT
Pending
Shipped

Practice 3 — Multiple Assignment#

Requirement#

एका statement मध्ये:

  • name = "Ravi"
  • city = "Nagpur"
  • country = "India"

assign करा.

Solution#

PYTHON
name, city, country = "Ravi", "Nagpur", "India"

print(name)
print(city)
print(country)

Practice 4 — Find Invalid Names#

खालील names classify करा:

TEXT
student_name
2student
student2
student-name
class
StudentName

Solution#

NameSyntax Valid?Comment
student_nameYesRecommended style
2studentNoStarts with digit
student2YesDigit after first character is allowed
student-nameNo as one identifierHyphen is not part of a normal identifier
classNoPython keyword
StudentNameYesValid, but not preferred style for normal variables

Practice 5 — Improve Naming Quality#

Rewrite:

PYTHON
n = "Aarav"
c = "Python Beginner Course"
p = 999

Solution#

PYTHON
student_name = "Aarav"
course_name = "Python Beginner Course"
course_price = 999

Why better?

Reader ला प्रत्येक value चा purpose लगेच समजतो.


Interview Preparation#

1. What is a variable in Python?

A variable is a name that refers to a value or object in a Python program.

What the interviewer is testing: Whether you understand that a Python variable is a name bound to a value rather than a permanently typed storage box.


2. How do you create a variable in Python?

A variable is created by assigning a value to a name.

PYTHON
student_name = "Asha"

Python does not require a separate declaration for ordinary variables before assignment.


3. What is variable assignment?

Variable assignment binds a name to a value using the assignment operator =.

PYTHON
score = 100

Here, the name score refers to the assigned value.


4. What is reassignment?

Reassignment means assigning a new value to an existing variable name.

PYTHON
status = "Pending"
status = "Completed"

After the second assignment, status refers to "Completed".


5. Can a Python variable be assigned a different kind of value later?

Yes.

PYTHON
value = 10
value = "Done"

Python does not require a fixed type declaration for an ordinary variable name.

A detailed discussion of Python data types belongs to the data-types topic.


6. What are the basic rules for naming variables in Python?

A variable name:

  • cannot start with a digit
  • can contain letters, digits and underscores
  • cannot be a Python reserved keyword
  • is case-sensitive
  • cannot contain spaces as part of one identifier

Python also supports valid Unicode identifiers, although simple ASCII names are commonly preferred for broad readability.


7. Are name, Name, and NAME the same variable?

No. Python identifiers are case-sensitive, so these are three different names.


8. What is the difference between a naming rule and a naming convention?

A naming rule determines whether an identifier is syntactically valid.

A naming convention is a style recommendation that improves consistency and readability.

For example:

PYTHON
2student = "Asha"

is invalid because it breaks a language rule.

PYTHON
studentName = "Asha"

can be valid, but:

PYTHON
student_name = "Asha"

better follows standard Python variable naming style.


9. What naming convention is normally used for Python variables?

Python variables normally use lowercase words separated by underscores when necessary.

Example:

PYTHON
student_name = "Asha"

This style is commonly called snake_case.


10. What is multiple assignment in Python?

Multiple assignment allows multiple names to receive values in a single assignment statement.

PYTHON
x, y = 10, 20

Here, x receives 10 and y receives 20.


11. How can you assign the same value to multiple variables?

You can use chained assignment:

PYTHON
x = y = z = 0

All three names are bound to the assigned value.


12. How can two variable values be swapped in Python?

Python supports direct swapping:

PYTHON
first, second = second, first

A separate temporary variable is not required.


13. What happens if you use a variable before assigning it?

If the name cannot be resolved, Python raises a NameError.

Example:

PYTHON
print(score)

If score has not been defined in the applicable scope, the statement fails.


14. Why are meaningful variable names important?

Meaningful names improve readability, maintainability, debugging and communication between developers.

For example:

PYTHON
course_price = 999

communicates more intent than:

PYTHON
p = 999

Quick Revision#

  • Variable म्हणजे value/object कडे refer करणारे नाव.
  • Basic assignment:
PYTHON
name = "Asha"
  • Reassignment:
PYTHON
status = "Pending"
status = "Completed"
  • Different values:
PYTHON
x, y = 10, 20
  • Same value:
PYTHON
x = y = z = 0
  • Swap:
PYTHON
x, y = y, x
  • Variable name digit ने सुरू करू नका.
  • spaces आणि normal identifier मध्ये hyphen वापरू नका.
  • Python keywords variable names म्हणून वापरू नका.
  • Names case-sensitive आहेत.
  • Normal variables साठी snake_case prefer करा.
  • Meaningful, concise names वापरा.
  • Naming rule आणि naming convention वेगळे आहेत.
  • Variable वापरण्यापूर्वी त्याला value assign झालेली असणे आवश्यक आहे.

You Should Now Be Able To#

आता तुम्ही:

  • Python variable explain करू शकता.
  • basic assignment लिहू शकता.
  • variable ची value reassign करू शकता.
  • multiple assignment वापरू शकता.
  • same value multiple names ला assign करू शकता.
  • two values swap करू शकता.
  • valid/invalid identifiers ओळखू शकता.
  • case sensitivity explain करू शकता.
  • keywords चुकीने variable names म्हणून वापरणे टाळू शकता.
  • snake_case variable names लिहू शकता.
  • unclear variable names improve करू शकता.
  • basic variable bugs diagnose करू शकता.
  • beginner-level Variables interview questions answer करू शकता.

Final Challenge#

Scenario#

तुम्ही simple course-registration program चा data तयार करत आहात.

Initial information:

TEXT
Student: Meera
Course: Python Beginner Course
Status: Registered
City: Pune

नंतर:

TEXT
Status becomes Active
City changes to Mumbai

Constraints#

  1. Meaningful snake_case names वापरा.
  2. Initial values assign करा.
  3. Status आणि city reassign करा.
  4. student_name आणि course_name एकाच statement मध्ये assign करण्याचा प्रयत्न करा.
  5. Final values print करा.

Hint 1#

PYTHON
a, b = value1, value2

Hint 2#

Existing variable update करण्यासाठी त्याच नावाला नवीन value assign करा.

Solution#

PYTHON
student_name, course_name = "Meera", "Python Beginner Course"
registration_status = "Registered"
student_city = "Pune"

registration_status = "Active"
student_city = "Mumbai"

print(student_name)
print(course_name)
print(registration_status)
print(student_city)

Expected Output:

TEXT
Meera
Python Beginner Course
Active
Mumbai

Reasoning#

या challenge मध्ये तुम्ही:

  • variable creation
  • assignment
  • multiple assignment
  • reassignment
  • meaningful naming
  • snake_case

हे chapter मधील core concepts एकत्र वापरले.